terraform workspace

Manage multiple Terraform state workspaces for environment isolation.

medium risk

interactive breakdown — edit the command and press Explain
$ 
⚠ Risks & cautions
What it does

Terraform workspaces maintain separate state files for the same configuration, enabling environment isolation (dev/staging/prod) without duplicating code. Each workspace has its own state. The current workspace name is accessible via `terraform.workspace`.

Examples
terraform workspace listList all workspaces (* marks current) · explain & risk-check →
terraform workspace new stagingCreate a new staging workspace · explain & risk-check →
terraform workspace select productionSwitch to production workspace · explain & risk-check →
terraform workspace showDisplay current workspace name · explain & risk-check →
terraform plan -var-file=${terraform workspace show}.tfvarsUse workspace name to select var file · explain & risk-check →
Pro tip

Always run `terraform workspace show` before plan/apply in production — verify you're in the right workspace before making changes. Add it to your pre-apply checklist.

Related
terraform plan terraform state terraform apply
Open the full explainer →More in Terraform, Ansible & IaC

Reference text is hand-written and may be incomplete — check man terraform for your version. Test destructive commands on a non-production system first.