Skip to content

Commit 78b208c

Browse files
RoseSecurityCopilotgoruha
authored
feat: support RDS-managed admin password via Secrets Manager (#64)
* feat: support RDS-managed admin password via Secrets Manager Add `manage_admin_user_password` variable to allow AWS RDS to manage the master user password in Secrets Manager. Adjust logic to ensure `admin_password` and `manage_admin_user_password` are mutually exclusive, and update module and locals to support this new option. This enhances security and flexibility for password management. * fix: adjust logic for admin password Co-authored-by: Copilot <[email protected]> * fix: update documentation Co-authored-by: Copilot <[email protected]> * chore: update logic * fix: update logic Co-authored-by: Copilot <[email protected]> * fix(terraform): use one() instead of join() for pet IDs Replaces join() with one() for random_pet admin_user and database_name IDs to ensure correct value selection. This prevents potential issues with unexpected list handling and aligns with Terraform's best practices for single value extraction. * fix: deduplicate logic Co-authored-by: Igor Rodionov <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Igor Rodionov <[email protected]>
1 parent 10d70b7 commit 78b208c

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

src/cluster-regional.tf

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ module "aurora_postgres_cluster" {
77
source = "cloudposse/rds-cluster/aws"
88
version = "2.2.0"
99

10-
cluster_type = "regional"
11-
engine = var.engine
12-
engine_version = var.engine_version
13-
engine_mode = var.engine_mode
14-
cluster_family = var.cluster_family
15-
instance_type = var.instance_type
16-
cluster_size = var.cluster_size
17-
promotion_tier = var.promotion_tier
18-
admin_user = local.admin_user
19-
admin_password = local.admin_password
10+
cluster_type = "regional"
11+
engine = var.engine
12+
engine_version = var.engine_version
13+
engine_mode = var.engine_mode
14+
cluster_family = var.cluster_family
15+
instance_type = var.instance_type
16+
cluster_size = var.cluster_size
17+
promotion_tier = var.promotion_tier
18+
admin_user = local.admin_user
19+
admin_password = local.admin_password
20+
manage_admin_user_password = var.manage_admin_user_password
2021

2122
db_name = local.database_name
2223
publicly_accessible = var.publicly_accessible

src/main.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ locals {
1414

1515
zone_id = module.dns_gbl_delegated.outputs.default_dns_zone_id
1616

17-
admin_user = length(var.admin_user) > 0 ? var.admin_user : join("", random_pet.admin_user[*].id)
18-
admin_password = length(var.admin_password) > 0 ? var.admin_password : join("", random_password.admin_password[*].result)
19-
database_name = length(var.database_name) > 0 ? var.database_name : join("", random_pet.database_name[*].id)
17+
# 1. If manage_admin_user_password is true, AWS manages the password (admin_password must be empty)
18+
# 2. If admin_password is provided, that value is used (manage_admin_user_password must be false)
19+
# 3. If both are unset/false/empty, the module creates a random password
20+
create_password = local.enabled && var.admin_password == "" && !var.manage_admin_user_password
21+
admin_password = var.manage_admin_user_password ? null : (local.create_password ? one(random_password.admin_password[*].result) : var.admin_password)
22+
23+
admin_user = length(var.admin_user) > 0 ? var.admin_user : one(random_pet.admin_user[*].id)
24+
database_name = length(var.database_name) > 0 ? var.database_name : one(random_pet.database_name[*].id)
2025

2126
cluster_dns_name_prefix = format("%v%v%v%v", module.this.name, module.this.delimiter, var.cluster_name, module.this.delimiter)
2227
cluster_dns_name = format("%v%v", local.cluster_dns_name_prefix, var.cluster_dns_name_part)

src/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ variable "admin_password" {
122122
}
123123
}
124124

125+
variable "manage_admin_user_password" {
126+
type = bool
127+
default = false
128+
description = "Set to true to allow RDS to manage the master user password in Secrets Manager. Cannot be set if admin_password is provided"
129+
nullable = false
130+
}
131+
125132
# https://aws.amazon.com/rds/aurora/pricing
126133
variable "instance_type" {
127134
type = string

0 commit comments

Comments
 (0)