Security asks, "who can see our secrets in Terraform state?" What do you answer?
AdvancedScenarioState Backends and Workspaces
Answer
Situation read → State stores resource attributes in plain text, including DB passwords and private keys.
What I'd do →
- Treat state read access as equal to secret access and restrict it to CI and a few admins.
- Encrypt at rest with KMS and enforce TLS in transit.
- Reduce secrets in state: RDS
manage_master_user_password, ephemeral values and write-only arguments on Terraform 1.10/1.11+, secrets fetched at runtime by apps. - Audit access with CloudTrail.
Why → sensitive = true only hides values in CLI output; it never removes them from state.
Interview tip → This question tests whether you know "sensitive" is redaction, not protection.
More on State Backends and Workspaces
Two engineers keep overwriting each other's changes because state is local. What's the fix?BeginnerSet up a production-grade S3 backend. What do you configure for locking?IntermediateHow do you harden the S3 bucket that holds Terraform state?IntermediateWho creates the state bucket itself, given Terraform needs it to exist before `init`?IntermediateA laptop apply and a CI apply start at the same time. What stops state corruption?IntermediateWhen are Terraform workspaces appropriate?Beginner