What are Terraform workspaces?
Answer
Terraform workspaces allow multiple state files from the same configuration, enabling different deployments (environments) from the same code. Commands: terraform workspace new staging, terraform workspace select prod, terraform workspace list. Each workspace has its own state file stored separately. Reference the workspace name in configuration: resource "aws_instance" "web" { tags = { Environment = terraform.workspace } }. Use different variable files per workspace: terraform apply -var-file="${terraform.workspace}.tfvars". Limitations: workspaces share the same backend; they are not isolated by default (same AWS account/region unless configured otherwise). For strong environment isolation (separate AWS accounts), use separate Terraform configurations or directories with separate backends rather than workspaces. Workspaces are best for short-lived feature branch environments, not permanent prod/staging separation.
Previous
What is the difference between Terraform and Ansible?
Next
What is the Terraform state locking mechanism?