Skip to content

Commit

Permalink
Merge pull request #111 from DopplerHQ/andre/aws-xform
Browse files Browse the repository at this point in the history
Add Name Transform to AWS SM and PS Syncs
  • Loading branch information
nmanoogian authored Dec 10, 2024
2 parents 2f779c1 + be9a057 commit 89c7414
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
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 @@ -97,6 +97,7 @@ resource "doppler_secrets_sync_aws_parameter_store" "backend_prod" {

- `delete_behavior` (String) The behavior to be performed on the secrets in the sync target when this resource is deleted or recreated. Either `leave_in_target` (default) or `delete_from_target`.
- `kms_key_id` (String) The AWS KMS key used to encrypt the parameter (ID, Alias, or ARN)
- `name_transform` (String) An optional secret name transformer (e.g. DOPPLER_CONFIG in lower-kebab would be doppler-config). Valid transformers: none, camel, upper-camel, lower-snake, tf-var, dotnet, dotnet-env, lower-kebab
- `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))
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 @@ -92,6 +92,7 @@ resource "doppler_secrets_sync_aws_secrets_manager" "backend_prod" {

- `delete_behavior` (String) The behavior to be performed on the secrets in the sync target when this resource is deleted or recreated. Either `leave_in_target` (default) or `delete_from_target`.
- `kms_key_id` (String) The AWS KMS key used to encrypt the secret (ID, Alias, or ARN)
- `name_transform` (String) An optional secret name transformer (e.g. DOPPLER_CONFIG in lower-kebab would be doppler-config). Valid transformers: none, camel, upper-camel, lower-snake, tf-var, dotnet, dotnet-env, lower-kebab
- `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.
Expand Down
2 changes: 2 additions & 0 deletions doppler/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,5 @@ func parseGroupMemberId(id string) (group string, memberType string, memberSlug
}
return tokens[0], tokens[1], tokens[2], nil
}

var NameTransformers = []string{"none", "camel", "upper-camel", "lower-snake", "tf-var", "dotnet", "dotnet-env", "lower-kebab"}
42 changes: 42 additions & 0 deletions doppler/resource_sync_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package doppler

import (
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
Expand Down Expand Up @@ -59,6 +62,23 @@ func resourceSyncAWSSecretsManager() *schema.Resource {
},
},

"name_transform": {
Description: fmt.Sprintf("An optional secret name transformer (e.g. DOPPLER_CONFIG in lower-kebab would be doppler-config). Valid transformers: %v", strings.Join(NameTransformers, ", ")),
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(NameTransformers, false),
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
if oldValue == "" && newValue == "none" {
return true
} else if oldValue == "none" && 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 @@ -94,6 +114,9 @@ func resourceSyncAWSSecretsManager() *schema.Resource {
if updateResourceTags, ok := d.GetOk("update_resource_tags"); ok {
payload["update_resource_tags"] = updateResourceTags
}
if nameTransform, ok := d.GetOk("name_transform"); ok {
payload["name_transform"] = nameTransform
}
if pathBehavior, ok := d.GetOk("path_behavior"); ok {
payload["use_doppler_suffix"] = pathBehavior == "add_doppler_suffix"
} else {
Expand Down Expand Up @@ -158,6 +181,22 @@ func resourceSyncAWSParameterStore() *schema.Resource {
}
},
},
"name_transform": {
Description: fmt.Sprintf("An optional secret name transformer (e.g. DOPPLER_CONFIG in lower-kebab would be doppler-config). Valid transformers: %v", strings.Join(NameTransformers, ", ")),
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(NameTransformers, false),
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
if oldValue == "" && newValue == "none" {
return true
} else if oldValue == "none" && newValue == "" {
return true
} else {
return newValue == oldValue
}
},
},
},
DataBuilder: func(d *schema.ResourceData) IntegrationData {
payload := map[string]interface{}{
Expand All @@ -172,6 +211,9 @@ func resourceSyncAWSParameterStore() *schema.Resource {
if updateResourceTags, ok := d.GetOk("update_resource_tags"); ok {
payload["update_resource_tags"] = updateResourceTags
}
if nameTransform, ok := d.GetOk("name_transform"); ok {
payload["name_transform"] = nameTransform
}
return payload
},
}
Expand Down

0 comments on commit 89c7414

Please sign in to comment.