Interview Prep/Terraform/Modules, Variables, Sensitive Values and Workspaces

A security review finds plaintext database passwords in the S3 state file, although variables are marked `sensitive = true`.

AdvancedTroubleshootingModules, Variables, Sensitive Values and Workspaces
Answer

Likely causes → sensitive only hides values in CLI output; state stores all arguments and attributes in plaintext JSON.

Diagnose → terraform state pull | jq '.. | .password? // empty'

Fix → Rotate the exposed credentials. Move to patterns that keep secrets out of state: manage_master_user_password = true on RDS (Secrets Manager), ephemeral resources (1.10+) and write-only arguments like password_wo (1.11+, provider support required).

Prevent → Encrypt state with KMS, restrict s3:GetObject on state to the pipeline role, and treat state as secret.

All Terraform questions Roadmap: Terraform

More on Modules, Variables, Sensitive Values and Workspaces