Skip to content

Commit 1d622a4

Browse files
authored
feat: Make the name suffix optional. (#5)
1 parent dedfa08 commit 1d622a4

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ to match your desired configuration. For example:
2020

2121
```hcl
2222
module "secrets" {
23-
source = "github.com/codeforamerica/tofu-modules-aws-secrets?ref=1.0.0"
23+
source = "github.com/codeforamerica/tofu-modules-aws-secrets?ref=1.1.0"
2424
2525
project = "my-project"
2626
environment = "dev"
@@ -56,14 +56,15 @@ tofu init -upgrade
5656

5757
## Inputs
5858

59-
| Name | Description | Type | Default | Required |
60-
|---------------------|---------------------------------------------------------------------------------------------|---------------|---------|----------|
61-
| project | Name of the project. | `string` | n/a | yes |
62-
| environment | Environment for the project. | `string` | `"dev"` | no |
63-
| key_recovery_period | Number of days to recover the KMS key after deletion. | `number` | `30` | no |
64-
| [secrets] | Secrets to be created. | `map(object)` | `{}` | no |
65-
| service | Optional service that these resources are supporting. Example: `"api"`, `"web"`, `"worker"` | `string` | n/a | no |
66-
| tags | Optional tags to be applied to all resources. | `list` | `[]` | no |
59+
| Name | Description | Type | Default | Required |
60+
|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|---------------|---------|----------|
61+
| project | Name of the project. | `string` | n/a | yes |
62+
| add_suffix | Apply a random suffix to the secret name. Useful when secrets may need to be replaced, but makes identify secrets by name alone more difficult. | `bool` | `true` | no |
63+
| environment | Environment for the project. | `string` | `"dev"` | no |
64+
| key_recovery_period | Number of days to recover the KMS key after deletion. | `number` | `30` | no |
65+
| [secrets] | Secrets to be created. | `map(object)` | `{}` | no |
66+
| service | Optional service that these resources are supporting. Example: `"api"`, `"web"`, `"worker"` | `string` | n/a | no |
67+
| tags | Optional tags to be applied to all resources. | `list` | `[]` | no |
6768

6869
### secrets
6970

main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module "secrets_manager" {
44

55
for_each = var.secrets
66

7-
name_prefix = each.value.name != "" ? "${each.value.name}-" : "${var.project}/${var.environment}/${var.service}/${each.key}-"
7+
name = coalesce(each.value.add_suffix, var.add_suffix) ? null : coalesce(each.value.name, "${var.project}/${var.environment}/${var.service}/${each.key}")
8+
name_prefix = coalesce(each.value.add_suffix, var.add_suffix) ? "${coalesce(each.value.name, "${var.project}/${var.environment}/${var.service}/${each.key}")}-" : null
89
create_random_password = each.value.create_random_password
910
description = each.value.description
1011
recovery_window_in_days = each.value.recovery_window

variables.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
variable "add_suffix" {
2+
type = bool
3+
description = "Apply a random suffix to the secret name. Useful when secrets may need to be replaced, but makes identify secrets by name alone more difficult."
4+
default = true
5+
}
6+
17
variable "environment" {
28
type = string
39
description = "Environment for the deployment."
@@ -23,9 +29,10 @@ variable "project" {
2329
# TODO: Support rotation.
2430
variable "secrets" {
2531
type = map(object({
32+
add_suffix = optional(bool, null)
2633
create_random_password = optional(bool, false)
2734
description = string
28-
name = optional(string, "")
35+
name = optional(string, null)
2936
recovery_window = optional(number, 30)
3037
start_value = optional(string, "{}")
3138
}))

0 commit comments

Comments
 (0)