How do you generate and manage the master password for a new RDS instance?
IntermediateScenarioSecrets Provisioners and Policy as Code
Answer
Situation read → You don't want a human choosing or seeing the password.
What I'd do →
- Prefer AWS-managed master credentials:
manage_master_user_password = truestores and rotates it in Secrets Manager. - Applications read it from Secrets Manager at runtime via IAM.
resource "aws_db_instance" "main" {
engine = "postgres"
username = "app_admin"
manage_master_user_password = true
}
Why → No password in code, tfvars or state, and rotation is automatic.
Interview tip → The alternative random_password puts the value in state.
More on Secrets Provisioners and Policy as Code
A developer hardcodes a DB password in `terraform.tfvars` and commits it. What do you do right now, and what's the long-term fix?BeginnerHow do you avoid Terraform persisting a secret in state when creating a secret in AWS Secrets Manager?AdvancedSomeone wants a `remote-exec` provisioner to configure servers after creation. What's your advice?BeginnerYou must run a one-off command after a resource is created, such as registering with an external system.IntermediateCompare Sentinel, OPA/Conftest and Checkov for policy as code.IntermediateHow do you prevent public S3 buckets from ever reaching production via Terraform?Intermediate