Terraform Workspaces Explained
Learn what Terraform workspaces are, when to use them, when not to use them, and how to manage multiple environments safely.
What is a Terraform workspace?
A workspace allows Terraform to use separate state instances for the same configuration. The default workspace is named default .
Workspace commands
terraform workspace list terraform workspace new dev terraform workspace select dev terraform workspace show
Using workspace in configuration
locals { environment = terraform.workspace }
When workspaces are useful
- Small projects with similar environments.
- Testing different copies of similar infrastructure.
- Simple dev/staging separation.
When workspaces are not ideal
- Large production environments.
- Projects needing strict separation.
- Different cloud accounts/subscriptions.
- Different backend access controls.
Common mistakes
- Applying to the wrong workspace.
- Using workspaces for completely different infrastructure.
- Not showing workspace name in scripts or CI/CD logs.
- Mixing production and dev accidentally.
Best practices
- Always check terraform workspace show .
- Use clear workspace names.
- Use separate backends for sensitive production environments.
- Document workspace usage.
Related guides
- Terraform Learning Path
- Terraform State File Explained
A workspace is state separation, not an access boundary
The commands operate on your configured backend and may create a new state namespace. Distinct workspaces do not provide separate permissions, credentials or blast radius by themselves; use separate accounts/projects and backend controls when strong environment isolation is required.
terraform workspace list
terraform workspace show
terraform workspace new dev
terraform workspace select devRelated Melochip article: https://melochip.com/posts/terraform-remote-backend-s3-azure-storage. Examples are illustrative and have not been independently executed.
Practical guidance and verification
Workspaces isolate state, not identity
Terraform CLI workspaces can hold different state instances for one configuration. They do not automatically create different AWS accounts, Azure subscriptions, access rules, networks, or secrets. Use separate root modules and cloud identities for environments requiring strong isolation, rather than relying on workspace names alone.
Choose your environment model
Workspaces can suit similar temporary environments, while separate directories and state backends often make production boundaries clearer. Have pipelines select the correct workspace explicitly and confirm both the selected backend and provider identity before planning. Never assume the default workspace is safe for deployment.
Operational verification
Document workspace ownership, who may apply changes, and where state backups live. Inspect the plan for unexpected cross-environment resources. Treat workspace deletion as a state-management operation with possible infrastructure consequences. See https://developer.hashicorp.com/terraform/cli/workspaces.
Join the discussion
0 CommentsAsk questions, add context, or share what worked.
More from Melochip Editorial
Learn what Playwright testing is, why modern QA teams use it, how testers can get started, and the major types...
8 min read · Updated Nov 16, 2026
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Updated Nov 16, 2026
Learn Kubernetes security best practices with RBAC, Secrets, ServiceAccounts, Pod securityContext, NetworkPoli...
6 min read · Updated Nov 16, 2026Related articles
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Updated Nov 16, 2026
Learn Kubernetes monitoring and logs with kubectl logs, events, metrics-server, top commands, Prometheus, Graf...
6 min read · Updated Nov 16, 2026
Learn Kubernetes Ingress with controllers, IngressClass, host and path routing, TLS, DNS, annotations, redirec...
8 min read · Updated Nov 16, 2026
Learn Kubernetes ConfigMaps and Secrets with YAML, environment variables, file mounts, update behavior, immuta...
8 min read · Updated Nov 16, 2026Stay in the loop. Get new Melochip articles
Receive Melochip article updates when new articles are available. Explicit opt-in only.
No comments yet. Start the discussion.