A laptop apply and a CI apply start at the same time. What stops state corruption?
IntermediateScenarioState Backends and Workspaces
Answer
Situation read → Concurrent writers are the classic cause of state corruption.
What I'd do →
- Rely on backend locking: the second run fails with "Error acquiring the state lock".
- Don't use
-lock=falsefor applies. - Restrict who can apply prod to the CI role only.
Why → The lock holds an ID and owner info; the second run waits (-lock-timeout=5m) or fails instead of interleaving writes.
Interview tip → The cleanest control is making CI the only identity allowed to write prod state.
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`?IntermediateWhen are Terraform workspaces appropriate?BeginnerCompare directories, workspaces and branches for environment separation.Intermediate