Terraform Multiple EnvironmentsTerraformTerraform Workspaces

Article & Tutorial

Terraform Workspaces Explained: Manage Multiple Environments Safely

Learn Terraform workspaces, workspace commands, use cases, limitations, common mistakes, and safe multi-environment best practices.

Isolated development, staging, and production infrastructure workspaces
Isolated development, staging, and production infrastructure workspaces
Contents

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.

example
terraform workspace list
terraform workspace show
terraform workspace new dev
terraform workspace select dev

Related Melochip article: https://melochip.com/posts/terraform-remote-backend-s3-azure-storage. Examples are illustrative and have not been independently executed.

Read related Terraform guide

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.

Did this help?

Yes No

Join the discussion

0 Comments

Ask questions, add context, or share what worked.

Sign in to join the discussion

No comments yet. Start the discussion.

More from Melochip Editorial

Related articles

Stay in the loop. Get new Melochip articles

Receive Melochip article updates when new articles are available. Explicit opt-in only.

No pre-checked boxes. Unsubscribe support is part of the subscriber foundation.