How do you harden the S3 bucket that holds Terraform state?
IntermediateScenarioState Backends and Workspaces
Answer
Situation read → State holds secrets and is the keys to the kingdom.
What I'd do →
- Turn on versioning so you can roll back a bad write.
- Enable default SSE-KMS encryption.
- Block all public access.
- Add a bucket policy that denies non-TLS requests and restricts access to the CI role and a break-glass role.
- Enable access logging or CloudTrail data events.
Why → Versioning is your undo; IAM scoping and encryption protect the secrets inside.
Interview tip → Put the bucket in a dedicated tooling account.
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?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?BeginnerCompare directories, workspaces and branches for environment separation.Intermediate