Two engineers keep overwriting each other's changes because state is local. What's the fix?
BeginnerScenarioState Backends and Workspaces
Answer
Situation read → Local terraform.tfstate on laptops means each person has a different truth.
What I'd do →
- Move state to a remote backend (S3, Azure Blob, GCS, or HCP Terraform).
- Enable locking so only one run mutates state at a time.
- Migrate with
terraform init -migrate-state.
Why → Remote state gives a single source of truth, access control, versioning and locking.
Interview tip → Say "state is shared, sensitive and must be locked".
More on State Backends and Workspaces
Set 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?BeginnerCompare directories, workspaces and branches for environment separation.Intermediate