How do you protect state for disaster recovery?
AdvancedScenarioState Backends and Workspaces
Answer
Situation read → State is a critical asset; regional loss shouldn't block recovery.
What I'd do →
- Enable versioning, and optionally Object Lock for compliance.
- Replicate the bucket cross-region (CRR) to a DR bucket in a separate account.
- Practice a restore, including pointing
-backend-configat the DR bucket. - Keep bootstrap code and runbooks outside the same region and account.
Why → Versioning covers mistakes, replication covers regional failure, and rehearsal proves it works.
Interview tip → You can't fix prod with Terraform in an outage if the state bucket is in the failing region.
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