Interview Prep/Terraform/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?

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 →

  1. Rotate the password immediately.
  2. Remove it from history (git filter-repo) and scan with gitleaks.
  3. Move the value to a secret manager and read at runtime, or use manage_master_user_password = true on RDS.
  4. Add a pre-commit secret scanner and ignore *.tfvars containing 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."

All Terraform questions

More on Secrets Provisioners and Policy as Code