Skip to content

Commit bf9b357

Browse files
authored
fix: adjust logic to address manage_master_user_password variable bugs (#131)
* fix: adjust logic to address var.manage_master_user_password bugs * fix(auth): update master password management logic Change the `manage_master_user_password` variable to use `null` as the default value instead of `false` and add validation to ensure it can only be set to `true` or `null`. Update related logic in password creation. * fix: update logic for master password creation * fix: update output logic * chore: update docs and comments
1 parent 3d222fa commit bf9b357

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
locals {
22
enabled = module.this.enabled
33
create_password = local.enabled && var.master_password == null && var.manage_master_user_password == null
4-
// If both `var.master_password` and `var.manage_master_user_password` are set to null, the module will create a random password
5-
// else if `var.master_password` is set to null - master_password is set to null as `manage_master_user_password` is set to true
6-
// else `local.master_password` is set to the value provided in `var.master_password`
4+
# 1. If manage_master_user_password is not null, AWS manages the password (master_password must be null)
5+
# 2. If master_password is provided, that value is used (manage_master_user_password must be null)
6+
# 3. If both are null, the module creates a random password
77
master_password = local.create_password ? one(random_password.password[*].result) : var.master_password
88
}
99

@@ -69,8 +69,9 @@ resource "aws_docdb_cluster" "default" {
6969
count = local.enabled ? 1 : 0
7070
cluster_identifier = module.this.id
7171
master_username = var.master_username
72-
# If `master_password` or `manage_master_user_password` is set, the other MUST be set to null, otherwise it will cause an error.
73-
master_password = local.master_password
72+
# Set master_password OR manage_master_user_password, but not both (one must be null)
73+
# manage_master_user_password=true enables AWS-managed passwords via Secrets Manager
74+
master_password = var.manage_master_user_password != null ? null : local.master_password
7475
manage_master_user_password = var.manage_master_user_password
7576
backup_retention_period = var.retention_period
7677
preferred_backup_window = var.preferred_backup_window

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ output "master_username" {
44
}
55

66
output "master_password" {
7-
value = var.manage_master_user_password != null ? join("", aws_docdb_cluster.default[*].master_password) : null
8-
description = "Password for the master DB user. If `manage_master_user_password` is set to true, this will be set to null."
7+
value = var.manage_master_user_password == true ? null : local.master_password
8+
description = "Password for the master DB user. If `manage_master_user_password` is set to true, this will be set to null and the password is managed by AWS in Secrets Manager."
99
sensitive = true
1010
}
1111

0 commit comments

Comments
 (0)