Skip to content

Commit 1e835c1

Browse files
committed
feat: Replace master_password with write-only master_password_wo/master_password_wo_version
1 parent 206ce5d commit 1e835c1

File tree

8 files changed

+36
-19
lines changed

8 files changed

+36
-19
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,10 @@ No modules.
369369
| <a name="input_iops"></a> [iops](#input\_iops) | The amount of Provisioned IOPS (input/output operations per second) to be initially allocated for each DB instance in the Multi-AZ DB cluster | `number` | `null` | no |
370370
| <a name="input_is_primary_cluster"></a> [is\_primary\_cluster](#input\_is\_primary\_cluster) | Determines whether cluster is primary cluster with writer instance (set to `false` for global cluster and replica clusters) | `bool` | `true` | no |
371371
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | The ARN for the KMS encryption key. When specifying `kms_key_id`, `storage_encrypted` needs to be set to `true` | `string` | `null` | no |
372-
| <a name="input_manage_master_user_password"></a> [manage\_master\_user\_password](#input\_manage\_master\_user\_password) | Set to true to allow RDS to manage the master user password in Secrets Manager. Cannot be set if `master_password` is provided | `bool` | `true` | no |
372+
| <a name="input_manage_master_user_password"></a> [manage\_master\_user\_password](#input\_manage\_master\_user\_password) | Set to true to allow RDS to manage the master user password in Secrets Manager. Cannot be set if `master_password_wo` is provided | `bool` | `true` | no |
373373
| <a name="input_manage_master_user_password_rotation"></a> [manage\_master\_user\_password\_rotation](#input\_manage\_master\_user\_password\_rotation) | Whether to manage the master user password rotation. By default, false on creation, rotation is managed by RDS. There is not currently a way to disable this on initial creation even when set to false. Setting this value to false after previously having been set to true will disable automatic rotation | `bool` | `false` | no |
374-
| <a name="input_master_password"></a> [master\_password](#input\_master\_password) | Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file. Required unless `manage_master_user_password` is set to `true` or unless `snapshot_identifier` or `replication_source_identifier` is provided or unless a `global_cluster_identifier` is provided when the cluster is the secondary cluster of a global database | `string` | `null` | no |
374+
| <a name="input_master_password_wo"></a> [master\_password\_wo](#input\_master\_password\_wo) | Write-Only required unless `manage_master_user_password` is set to `true`, a `snapshot_identifier`, `replication_source_identifier`, or unless a `global_cluster_identifier` is provided when the cluster is the "secondary" cluster of a global database) Password for the master DB user | `string` | `null` | no |
375+
| <a name="input_master_password_wo_version"></a> [master\_password\_wo\_version](#input\_master\_password\_wo\_version) | Used together with `master_password_wo` to trigger an update. Increment this value when an update to the `master_password_wo` is required | `string` | `null` | no |
375376
| <a name="input_master_user_password_rotate_immediately"></a> [master\_user\_password\_rotate\_immediately](#input\_master\_user\_password\_rotate\_immediately) | Specifies whether to rotate the secret immediately or wait until the next scheduled rotation window | `bool` | `null` | no |
376377
| <a name="input_master_user_password_rotation_automatically_after_days"></a> [master\_user\_password\_rotation\_automatically\_after\_days](#input\_master\_user\_password\_rotation\_automatically\_after\_days) | Specifies the number of days between automatic scheduled rotations of the secret. Either `master_user_password_rotation_automatically_after_days` or `master_user_password_rotation_schedule_expression` must be specified | `number` | `null` | no |
377378
| <a name="input_master_user_password_rotation_duration"></a> [master\_user\_password\_rotation\_duration](#input\_master\_user\_password\_rotation\_duration) | The length of the rotation window in hours. For example, 3h for a three hour window | `string` | `null` | no |

docs/UPGRADE-10.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ If you find a bug, please open an issue with supporting configuration to reprodu
88
- Terraform `v1.11` is now minimum supported version to support write-only (`wo_*`) attributes.
99
- AWS provider `v6.18` is now minimum supported version
1010
- The underlying `aws_security_group_rule` resources has been replaced with `aws_vpc_security_group_ingress_rule` and `aws_vpc_security_group_egress_rule` to allow for more flexibility in defining security group rules.
11+
- `master_password` is no longer supported and only the write-only equivalent is supported (`master_password_wo` and `master_password_wo_version`).
1112

1213
## Additional changes
1314

@@ -45,6 +46,7 @@ If you find a bug, please open an issue with supporting configuration to reprodu
4546
- `endpoints.cluster_endpoint_identifier` was previously `endpoints.identifier`
4647
- `endpoints.custom_endpoint_type` was previously `endpoints.type`
4748
- `role_associations` was previously `iam_roles`
49+
- `master_password` replaced with `master_password_wo` and `master_password_wo_version`
4850
- The variables for DB shard group have been nested under a single, top-level `shard_group` variable:
4951
- `create_shard_group` removed - set `shard_group` to `null` to disable or provide an object to enable
5052
- `compute_redundancy` -> `shard_group.compute_redundancy`

examples/global-cluster/main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ module "aurora_primary" {
6262
}
6363

6464
# Global clusters do not support managed master user password
65-
manage_master_user_password = false
66-
master_password = random_password.master.result
65+
master_password_wo = random_password.master.result
66+
master_password_wo_version = 1
6767

6868
skip_final_snapshot = true
6969

@@ -95,7 +95,8 @@ module "aurora_secondary" {
9595
}
9696

9797
# Global clusters do not support managed master user password
98-
master_password = random_password.master.result
98+
master_password_wo = random_password.master.result
99+
master_password_wo_version = 1
99100

100101
skip_final_snapshot = true
101102

examples/limitless/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ module "aurora" {
4343
}
4444

4545
# aurora limitless clusters do not support managed master user password
46-
master_username = "root"
47-
manage_master_user_password = false
48-
master_password = random_password.master.result
46+
master_username = "root"
47+
master_password_wo = random_password.master.result
48+
master_password_wo_version = 1
4949

5050
vpc_id = module.vpc.vpc_id
5151
db_subnet_group_name = module.vpc.database_subnet_group_name

examples/serverless/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ module "aurora_postgresql" {
4141
}
4242

4343
# Serverless v1 clusters do not support managed master user password
44-
manage_master_user_password = false
45-
master_password = random_password.master.result
44+
master_password_wo = random_password.master.result
45+
master_password_wo_version = 1
4646

4747
cluster_monitoring_interval = 60
4848

@@ -85,8 +85,8 @@ module "aurora_mysql" {
8585
}
8686

8787
# Serverless v1 clusters do not support managed master user password
88-
manage_master_user_password = false
89-
master_password = random_password.master.result
88+
master_password_wo = random_password.master.result
89+
master_password_wo_version = 1
9090

9191
cluster_monitoring_interval = 60
9292

main.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ resource "aws_db_subnet_group" "this" {
3535
# Cluster
3636
################################################################################
3737

38+
locals {
39+
use_master_password = var.is_primary_cluster && !var.manage_master_user_password && var.global_cluster_identifier == null
40+
use_managed_master_password = var.manage_master_user_password && var.global_cluster_identifier == null
41+
}
42+
3843
resource "aws_rds_cluster" "this" {
3944
count = local.create ? 1 : 0
4045

@@ -76,9 +81,10 @@ resource "aws_rds_cluster" "this" {
7681
# iam_roles has been removed from this resource and instead will be used with aws_rds_cluster_role_association below to avoid conflicts per docs
7782
iops = var.iops
7883
kms_key_id = var.kms_key_id
79-
manage_master_user_password = var.global_cluster_identifier == null && var.manage_master_user_password ? var.manage_master_user_password : null
80-
master_user_secret_kms_key_id = var.global_cluster_identifier == null && var.manage_master_user_password ? var.master_user_secret_kms_key_id : null
81-
master_password = var.is_primary_cluster && !var.manage_master_user_password ? var.master_password : null
84+
manage_master_user_password = local.use_managed_master_password ? var.manage_master_user_password : null
85+
master_user_secret_kms_key_id = local.use_managed_master_password ? var.master_user_secret_kms_key_id : null
86+
master_password_wo = local.use_master_password ? var.master_password_wo : null
87+
master_password_wo_version = local.use_master_password ? var.master_password_wo_version : null
8288
master_username = var.is_primary_cluster ? var.master_username : null
8389
monitoring_interval = var.cluster_monitoring_interval
8490
monitoring_role_arn = var.create_monitoring_role && var.cluster_monitoring_interval > 0 ? try(aws_iam_role.rds_enhanced_monitoring[0].arn, null) : var.monitoring_role_arn

variables.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ variable "kms_key_id" {
271271
}
272272

273273
variable "manage_master_user_password" {
274-
description = "Set to true to allow RDS to manage the master user password in Secrets Manager. Cannot be set if `master_password` is provided"
274+
description = "Set to true to allow RDS to manage the master user password in Secrets Manager. Cannot be set if `master_password_wo` is provided"
275275
type = bool
276276
default = true
277277
}
@@ -282,8 +282,14 @@ variable "master_user_secret_kms_key_id" {
282282
default = null
283283
}
284284

285-
variable "master_password" {
286-
description = "Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file. Required unless `manage_master_user_password` is set to `true` or unless `snapshot_identifier` or `replication_source_identifier` is provided or unless a `global_cluster_identifier` is provided when the cluster is the secondary cluster of a global database"
285+
variable "master_password_wo" {
286+
description = "Write-Only required unless `manage_master_user_password` is set to `true`, a `snapshot_identifier`, `replication_source_identifier`, or unless a `global_cluster_identifier` is provided when the cluster is the \"secondary\" cluster of a global database) Password for the master DB user"
287+
type = string
288+
default = null
289+
}
290+
291+
variable "master_password_wo_version" {
292+
description = "Used together with `master_password_wo` to trigger an update. Increment this value when an update to the `master_password_wo` is required"
287293
type = string
288294
default = null
289295
}

wrappers/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ module "wrapper" {
7777
kms_key_id = try(each.value.kms_key_id, var.defaults.kms_key_id, null)
7878
manage_master_user_password = try(each.value.manage_master_user_password, var.defaults.manage_master_user_password, true)
7979
manage_master_user_password_rotation = try(each.value.manage_master_user_password_rotation, var.defaults.manage_master_user_password_rotation, false)
80-
master_password = try(each.value.master_password, var.defaults.master_password, null)
80+
master_password_wo = try(each.value.master_password_wo, var.defaults.master_password_wo, null)
81+
master_password_wo_version = try(each.value.master_password_wo_version, var.defaults.master_password_wo_version, null)
8182
master_user_password_rotate_immediately = try(each.value.master_user_password_rotate_immediately, var.defaults.master_user_password_rotate_immediately, null)
8283
master_user_password_rotation_automatically_after_days = try(each.value.master_user_password_rotation_automatically_after_days, var.defaults.master_user_password_rotation_automatically_after_days, null)
8384
master_user_password_rotation_duration = try(each.value.master_user_password_rotation_duration, var.defaults.master_user_password_rotation_duration, null)

0 commit comments

Comments
 (0)