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?
BeginnerScenarioSecrets Provisioners and Policy as Code
Answer
Situation read → A credential in Git history is compromised, even if you delete the file.
What I'd do →
- Rotate the password immediately.
- Remove it from history (
git filter-repo) and scan withgitleaks. - Move the value to a secret manager and read at runtime, or use
manage_master_user_password = trueon RDS. - Add a pre-commit secret scanner and ignore
*.tfvarscontaining secrets.
Why → Deleting a file doesn't remove it from history or forks; rotation is the only real fix.
Interview tip → "Rotate first, clean later."
More on Secrets Provisioners and Policy as Code
How 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.IntermediateHow do you generate and manage the master password for a new RDS instance?IntermediateCompare Sentinel, OPA/Conftest and Checkov for policy as code.IntermediateHow do you prevent public S3 buckets from ever reaching production via Terraform?Intermediate