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 ability to update AWS resource tags for SM and PS syncs #106

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/resources/secrets_sync_aws_parameter_store.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ resource "doppler_secrets_sync_aws_parameter_store" "backend_prod" {
- `kms_key_id` (String) The AWS KMS key used to encrypt the parameter (ID, Alias, or ARN)
- `secure_string` (Boolean) Whether or not the parameters are stored as a secure string
- `tags` (Map of String) AWS tags to attach to the parameters
- `update_resource_tags` (String) Behavior for AWS resource tags on updates (never update, upsert tags (leaving non-Doppler tags alone), replace tags (remove non-Doppler tags))

### Read-Only

Expand Down
1 change: 1 addition & 0 deletions docs/resources/secrets_sync_aws_secrets_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ resource "doppler_secrets_sync_aws_secrets_manager" "backend_prod" {
- `path_behavior` (String) The behavior to modify the provided path. Either `add_doppler_suffix` (default) which appends `doppler` to the provided path or `none` which leaves the path unchanged.
- `tags` (Map of String) AWS tags to attach to the secrets
- `update_metadata` (Boolean) If enabled, Doppler will update the AWS secret metadata (e.g. KMS key) during every sync. If disabled, Doppler will only set secret metadata for new AWS secrets. Note that Doppler never updates tags for existing AWS secrets.
- `update_resource_tags` (String) Behavior for AWS resource tags on updates (never update, upsert tags (leaving non-Doppler tags alone), replace tags (remove non-Doppler tags))

### Read-Only

Expand Down
40 changes: 40 additions & 0 deletions doppler/resource_sync_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ func resourceSyncAWSSecretsManager() *schema.Resource {
Optional: true,
ForceNew: true,
},

"update_resource_tags": {
Description: "Behavior for AWS resource tags on updates (never update, upsert tags (leaving non-Doppler tags alone), replace tags (remove non-Doppler tags))",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"never", "upsert", "replace"}, false),
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
if oldValue == "" && newValue == "never" {
return true
} else if oldValue == "never" && newValue == "" {
return true
} else {
return newValue == oldValue
}
},
},

"path_behavior": {
Description: "The behavior to modify the provided path. Either `add_doppler_suffix` (default) which appends `doppler` to the provided path or `none` which leaves the path unchanged.",
Type: schema.TypeString,
Expand Down Expand Up @@ -73,6 +91,9 @@ func resourceSyncAWSSecretsManager() *schema.Resource {
if updateMetadata, ok := d.GetOk("update_metadata"); ok {
payload["update_metadata"] = updateMetadata
}
if updateResourceTags, ok := d.GetOk("update_resource_tags"); ok {
payload["update_resource_tags"] = updateResourceTags
}
if pathBehavior, ok := d.GetOk("path_behavior"); ok {
payload["use_doppler_suffix"] = pathBehavior == "add_doppler_suffix"
} else {
Expand Down Expand Up @@ -121,6 +142,22 @@ func resourceSyncAWSParameterStore() *schema.Resource {
Optional: true,
ForceNew: true,
},
"update_resource_tags": {
Description: "Behavior for AWS resource tags on updates (never update, upsert tags (leaving non-Doppler tags alone), replace tags (remove non-Doppler tags))",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"never", "upsert", "replace"}, false),
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
if oldValue == "" && newValue == "never" {
return true
} else if oldValue == "never" && newValue == "" {
return true
} else {
return newValue == oldValue
}
},
},
},
DataBuilder: func(d *schema.ResourceData) IntegrationData {
payload := map[string]interface{}{
Expand All @@ -132,6 +169,9 @@ func resourceSyncAWSParameterStore() *schema.Resource {
if kmsKeyId, ok := d.GetOk("kms_key_id"); ok {
payload["kms_key_id"] = kmsKeyId
}
if updateResourceTags, ok := d.GetOk("update_resource_tags"); ok {
payload["update_resource_tags"] = updateResourceTags
}
return payload
},
}
Expand Down