Skip to content
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

Add Secrets Sync support to TFVP #2098

Merged
merged 26 commits into from
Jan 17, 2024
Merged

Conversation

vinay-gopalan
Copy link
Contributor

@vinay-gopalan vinay-gopalan commented Nov 23, 2023

Description

Adds the following resources:

  • AWS Secrets sync destination (with test)
  • Github Secrets sync destination (with test)
  • GCP Secrets sync destination (with test)
  • Azure Secrets sync destination (with test)
  • Vercel Secrets sync destination (with test)
  • Secrets Sync Association (does not have a test since a test would leave dangling resources in external systems that TFVP has no way of cleaning up. Tested manually with multiple TF config files)

Checklist

  • Added CHANGELOG entry (only for user-facing changes)
  • Acceptance tests where run against all supported Vault Versions

@vinay-gopalan vinay-gopalan requested a review from a team November 23, 2023 02:41
Copy link
Member

@robmonte robmonte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid so far

vault/provider.go Show resolved Hide resolved
vault/resource_gh_secrets_sync_destination.go Outdated Show resolved Hide resolved
vault/resource_aws_secrets_sync_destination.go Outdated Show resolved Hide resolved
vault/resource_aws_secrets_sync_destination.go Outdated Show resolved Hide resolved
@vinay-gopalan vinay-gopalan requested a review from a team December 21, 2023 00:50
Copy link
Contributor

@maxcoulombe maxcoulombe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Most of my comments are nits, some edge cases we can handle is follow-up PRs or just providing some context along the way.

The only aspect I'd be keen to explore before we merge is to try to make the destination methods generic to remove an important amount of boilerplate code and make new destinations or additional fields easier to fit in in the future. Let me know if that make sense, I'm also happy to pair on this if you want!

vault/resource_aws_secrets_sync_destination.go Outdated Show resolved Hide resolved
vault/resource_aws_secrets_sync_destination.go Outdated Show resolved Hide resolved
vault/resource_aws_secrets_sync_destination.go Outdated Show resolved Hide resolved
log.Printf("[DEBUG] Deleted AWS sync destination at %q", path)

return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recreate scenarios like modifying the region do not work at the moment with the following error:

│ Namespace: my-ns-1
│ URL: DELETE http://localhost:8200/v1/sys/sync/destinations/aws-sm/my-dest-1
│ Code: 400. Errors:
│ 
│ * store cannot be deleted because it is still managing secrets

I believe that with @robmonte 's new ?purge parameter available when deleting an application we could gracefully handle the teardown flow by passing this param and polling the destination until the purge operation gets completed by the backend. This can be a separate ticket/PR but food for thought on a possible solution!

vault/resource_aws_secrets_sync_destination.go Outdated Show resolved Hide resolved
vault/resource_secrets_sync_association.go Show resolved Hide resolved
vault/resource_secrets_sync_association.go Outdated Show resolved Hide resolved
vault/resource_secrets_sync_association.go Show resolved Hide resolved
vault/resource_secrets_sync_association.go Outdated Show resolved Hide resolved
vault/resource_secrets_sync_association.go Show resolved Hide resolved
path := secretsSyncDestinationPath(d.Id(), typ)

log.Printf("[DEBUG] Deleting sync destination at %q", path)
_, err := client.Logical().DeleteWithContext(ctx, path)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will probably add ?purge parameter to the delete method in a follow-up PR for robustness

internal/provider/schema_util.go Outdated Show resolved Hide resolved
internal/sync/secrets_sync.go Outdated Show resolved Hide resolved
vault/resource_secrets_sync_association.go Outdated Show resolved Hide resolved
vault/resource_secrets_sync_gcp_destination.go Outdated Show resolved Hide resolved

func awsSecretsSyncDestinationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
return syncutil.SyncDestinationDelete(ctx, d, meta, awsSyncType)
}
Copy link
Contributor

@maxcoulombe maxcoulombe Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So clean with the generic utility methods! gg

Copy link
Contributor

@maxcoulombe maxcoulombe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GG, this is super clean and works very well.

Custom_tags & secret_name_template should be editable and should be in the Azure schema. Besides that I think everything is perfect!

@vinay-gopalan vinay-gopalan added this to the 3.25.0 milestone Jan 17, 2024
@vinay-gopalan vinay-gopalan merged commit cd86403 into main Jan 17, 2024
13 checks passed
@vinay-gopalan vinay-gopalan deleted the VAULT-18672/aws-secrets-sync-loop branch January 17, 2024 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants