State is 40 MB and operations are slow. What do you do?
IntermediateScenarioState Backends and Workspaces
Answer
Situation read → Large state means slow refresh, slow locking and a large blast radius.
What I'd do →
- Identify heavy resource types with
terraform state list | cut -d. -f1-2 | sort | uniq -c | sort -rn. - Split by lifecycle into multiple states.
- Remove noisy resources such as thousands of IAM policy attachments from a hot path by moving them to their own stack.
- Use
-refresh=falseonly for local iteration.
Why → Plan time scales with resource count; smaller states are faster and safer.
Interview tip → Splitting is a design fix, flags are a patch.
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