-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add support for AWS-managed master password #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This update introduces the `manage_master_user_password` variable, allowing the module to use AWS Secrets Manager for managing the DocumentDB master user password. The logic in `main.tf` is updated to handle three cases: 1) AWS-managed password, 2) user-provided password, and 3) auto-generated password. Also updates the AWS provider version constraint and fixes a typo in the random_password resource.
|
/terratest |
WalkthroughIntroduces a conditional master password management flow, adds a new input variable manage_master_user_password, adjusts module wiring to pass this input and conditionally set master_password, updates random_password character option from number to numeric, and tightens AWS provider constraint to >= 5.29.0 and < 6.0.0. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor U as User/Caller
participant T as Terraform Root Module
participant RP as random_password
participant M as module "documentdb_cluster"
participant SM as AWS Secrets Manager
U->>T: Apply with variables (master_password, manage_master_user_password)
alt manage_master_user_password == true
T-->>M: master_password = null, manage_master_user_password = true
M->>SM: Manage master user password in Secrets Manager
else master_password == null and manage_master_user_password == null
T->>RP: Generate random master password
RP-->>T: random value
T-->>M: master_password = local computed value, manage_master_user_password = null
else master_password provided
T-->>M: master_password = provided value, manage_master_user_password = null
end
note over M,SM: Module behavior uses either SM-managed secret or provided/computed password
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/ssm.tf (1)
9-24: Do not generate or store a password when AWS manages it or user provides oneBoth random_password.master_password and aws_ssm_parameter.master_password are created whenever local.enabled, causing:
- Unused secrets generated and stored in SSM when manage_master_user_password = true.
- A random secret stored even when a user-supplied master_password is used.
Gate these resources on local.create_password to align with main.tf logic and avoid leaking/creating unused secrets.
resource "random_password" "master_password" { - count = local.enabled ? 1 : 0 + count = local.create_password ? 1 : 0 # character length length = 33 special = false upper = true lower = true numeric = true min_special = 0 min_upper = 1 min_lower = 1 min_numeric = 1 } resource "aws_ssm_parameter" "master_password" { - count = local.enabled ? 1 : 0 + count = local.create_password ? 1 : 0 name = "/${module.this.name}/master_password" type = "SecureString" value = one(random_password.master_password[*].result) }Also applies to: 26-32
🧹 Nitpick comments (2)
src/main.tf (1)
3-8: Password selection logic LGTM; add a mutual‑exclusivity guardCurrent logic correctly handles the three cases. However, if both master_password and manage_master_user_password=true are set, the user password is silently ignored. Add a precondition to fail fast.
# For Terraform >= 1.2 module "documentdb_cluster" { # ... lifecycle { precondition { condition = !(var.manage_master_user_password == true && var.master_password != null) error_message = "Do not set both master_password and manage_master_user_password=true." } } # ... }src/variables.tf (1)
43-51: Validation matches intended semanticsAllowing only null or true prevents accidental false and documents intent. Pair with a module-level precondition to forbid setting this alongside master_password.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/main.tf(2 hunks)src/ssm.tf(1 hunks)src/variables.tf(1 hunks)src/versions.tf(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Summary
🔇 Additional comments (2)
src/main.tf (1)
35-39: Module wiring correct; confirm module input & provider constraint
Null master_password when manage_master_user_password is set matches AWS semantics. Manually verify that cloudposse/documentdb-cluster/aws v0.30.2 declares the manage_master_user_password input and constrains the AWS provider to ≥ 5.29.0.src/versions.tf (1)
7-7: Verify Terraform core version constraint
Confirm AWS provider v5.29.0’s minimum Terraform core version via the Terraform Registry or HashiCorp release notes (likely ≥ 1.3.0), then updaterequired_versionaccordingly (e.g., tighten from “>= 1.0.0” to the verified minimum).
|
These changes were released in v1.537.4. |
what
This updates the module to support AWS-managed master user passwords for DocumentDB clusters, improves password management logic, and updates provider requirements. The most significant changes are grouped below:
Password Management Enhancements:
manage_master_user_passwordto enable AWS Secrets Manager to manage the master user password, with validation to ensure onlytrueornullare accepted.src/main.tfto handle three cases: AWS-managed password, user-provided password, or module-generated random password.documentdb_clustermodule configuration to pass the correct values formaster_passwordandmanage_master_user_passwordbased on the new logic.Provider and Resource Updates:
random_passwordresource by changing the argument fromnumbertonumericfor correct password generation.why
manage_master_user_passwordvariable, allowing the module to use AWS Secrets Manager for managing the DocumentDB master user passwordreferences
manage_master_user_passwordvariable bugs cloudposse/terraform-aws-documentdb-cluster#131Summary by CodeRabbit