-
Notifications
You must be signed in to change notification settings - Fork 15
Sync terraform provider with recent Akeyless API changes #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
avivm-lang
merged 8 commits into
master
from
ASM-18722-sync-terraform-provider-akeyless
Jul 20, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e1fabe6
sync sdk delta v5.0.28 vs v5.0.30
avivm-lang cff8b9f
bump version
avivm-lang 2d8f40b
add default value for delete_protection flag
avivm-lang f97a035
add more tests
avivm-lang 44725f6
define gateway version since its download outdated by default
avivm-lang 047781f
remove target_name from non hashi migrations and review fixes
avivm-lang d229d83
explicit gateway version
avivm-lang 4139bd7
fixes
avivm-lang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| // generated file | ||
| package akeyless | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| akeyless_api "github.com/akeylesslabs/akeyless-go/v5" | ||
| "github.com/akeylesslabs/terraform-provider-akeyless/akeyless/common" | ||
| "github.com/google/uuid" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
| ) | ||
|
|
||
| func resourceCertificateDiscovery() *schema.Resource { | ||
| return &schema.Resource{ | ||
| Description: "Certificate Discovery resource. Starts a certificate discovery scan and saves results under the target location. Destroying this resource removes it from Terraform state only and does not delete discovered certificates.", | ||
| Create: resourceCertificateDiscoveryCreate, | ||
| Read: resourceCertificateDiscoveryRead, | ||
| Delete: resourceCertificateDiscoveryDelete, | ||
| Importer: &schema.ResourceImporter{ | ||
| State: resourceCertificateDiscoveryImport, | ||
| }, | ||
| Schema: map[string]*schema.Schema{ | ||
| "hosts": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| ForceNew: true, | ||
| Description: "A comma separated list of IPs, CIDR ranges, or DNS names to scan", | ||
| }, | ||
| "port_ranges": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| ForceNew: true, | ||
| Default: "443", | ||
| Description: "A comma separated list of port ranges. Example: 80,8080-8085", | ||
| }, | ||
| "target_location": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| ForceNew: true, | ||
| Description: "The results will be saved in this folder", | ||
| DiffSuppressFunc: common.DiffSuppressOnLeadingSlash, | ||
| }, | ||
| "expiration_event_in": { | ||
| Type: schema.TypeSet, | ||
| Optional: true, | ||
| ForceNew: true, | ||
| Description: "How many days before the expiration of the certificate would you like to be notified. To specify multiple events, repeat this argument.", | ||
| Elem: &schema.Schema{Type: schema.TypeString}, | ||
| }, | ||
|
tuvia-akeyless marked this conversation as resolved.
|
||
| "protection_key": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| ForceNew: true, | ||
| Description: "The name of the key that protects the certificate value (if empty, the account default key will be used)", | ||
| }, | ||
| "count_new": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, | ||
| Description: "Number of new certificates discovered", | ||
| }, | ||
| "count_existing": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, | ||
| Description: "Number of existing certificates updated", | ||
| }, | ||
| "count_hosts": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, | ||
| Description: "Number of hosts scanned", | ||
| }, | ||
| "count_failed": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, | ||
| Description: "Number of failed scan targets", | ||
| }, | ||
| "item_names": { | ||
| Type: schema.TypeList, | ||
| Computed: true, | ||
| Description: "Names of certificate items created or updated by the discovery", | ||
| Elem: &schema.Schema{Type: schema.TypeString}, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func resourceCertificateDiscoveryCreate(d *schema.ResourceData, m interface{}) error { | ||
| provider := m.(*providerMeta) | ||
| client := *provider.client | ||
| token := *provider.token | ||
|
|
||
| ctx := context.Background() | ||
| hosts := strings.ReplaceAll(d.Get("hosts").(string), " ", "") | ||
| portRanges := strings.ReplaceAll(d.Get("port_ranges").(string), " ", "") | ||
| targetLocation := d.Get("target_location").(string) | ||
| expirationEventInSet := d.Get("expiration_event_in").(*schema.Set) | ||
| expirationEventIn := common.ExpandStringList(expirationEventInSet.List()) | ||
| protectionKey := d.Get("protection_key").(string) | ||
|
|
||
| if hosts == "" { | ||
| return fmt.Errorf("hosts cannot be empty") | ||
| } | ||
|
|
||
| body := akeyless_api.CertificateDiscovery{ | ||
| Hosts: hosts, | ||
| TargetLocation: targetLocation, | ||
| Token: &token, | ||
| } | ||
| common.GetAkeylessPtr(&body.PortRanges, portRanges) | ||
| common.GetAkeylessPtr(&body.ExpirationEventIn, expirationEventIn) | ||
| common.GetAkeylessPtr(&body.ProtectionKey, protectionKey) | ||
|
|
||
| out, resp, err := client.CertificateDiscovery(ctx).Body(body).Execute() | ||
| if err != nil { | ||
| return common.HandleError("can't run certificate discovery", resp, err) | ||
| } | ||
|
|
||
| countNew, countExisting, countHosts, countFailed := 0, 0, 0, 0 | ||
| itemNames := []string{} | ||
| if out != nil && out.Results != nil { | ||
| results := out.Results | ||
| if results.CountNew != nil { | ||
| countNew = int(*results.CountNew) | ||
| } | ||
| if results.CountExisting != nil { | ||
| countExisting = int(*results.CountExisting) | ||
| } | ||
| if results.CountHosts != nil { | ||
| countHosts = int(*results.CountHosts) | ||
| } | ||
| if results.CountFailed != nil { | ||
| countFailed = int(*results.CountFailed) | ||
| } | ||
| if results.ItemNames != nil { | ||
| itemNames = results.ItemNames | ||
| } | ||
| } | ||
| if err := d.Set("count_new", countNew); err != nil { | ||
| return err | ||
| } | ||
| if err := d.Set("count_existing", countExisting); err != nil { | ||
| return err | ||
| } | ||
| if err := d.Set("count_hosts", countHosts); err != nil { | ||
| return err | ||
| } | ||
| if err := d.Set("count_failed", countFailed); err != nil { | ||
| return err | ||
| } | ||
| if err := d.Set("item_names", itemNames); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| d.SetId(uuid.New().String()) | ||
| return nil | ||
| } | ||
|
|
||
| func resourceCertificateDiscoveryRead(d *schema.ResourceData, m interface{}) error { | ||
| // Discovery is a one-shot scan with no get/describe API; retain Terraform state. | ||
| return nil | ||
| } | ||
|
|
||
| func resourceCertificateDiscoveryDelete(d *schema.ResourceData, m interface{}) error { | ||
| // Destroying the resource only removes it from Terraform state. | ||
| // Discovered certificate items are left intact. | ||
| d.SetId("") | ||
| return nil | ||
| } | ||
|
|
||
| func resourceCertificateDiscoveryImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { | ||
| return nil, fmt.Errorf("certificate discovery cannot be imported because it is a one-shot scan with no remote identity") | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.