Interview Prep/Terraform/State Backends and Workspaces

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 →

  1. Use CLI workspaces for short-lived copies of the same stack, such as a feature-branch environment or PR preview.
  2. 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.

All Terraform questions Roadmap: Terraform in production

More on State Backends and Workspaces