When are Terraform workspaces appropriate?
BeginnerScenarioState Backends and Workspaces
Answer
Situation read → A teammate wants to use workspaces for dev/stage/prod.
What I'd do →
- Use CLI workspaces for short-lived copies of the same stack, such as a feature-branch environment or PR preview.
- Use separate directories or backends for long-lived environments with different access rules.
terraform workspace new pr-421
terraform apply -var="name_suffix=pr-421"
terraform workspace select default
Why → CLI workspaces share the same backend and code, so credentials and blast radius are shared, and it's easy to apply to the wrong one.
Interview tip → HCP Terraform "workspaces" are a different thing: independent state, variables and permissions.
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?IntermediateCompare directories, workspaces and branches for environment separation.Intermediate