Terraform Tutorial — What Are Workspaces?
Workspaces create isolated state for the same configuration. Each workspace has its own terraform.tfstate, so resources in one workspace don’t interfere with another.
The Default Workspace
Every Terraform project starts in a workspace called default:
$ terraform workspace show
default
When you run terraform apply, state is stored in terraform.tfstate.
Creating a New Workspace
$ terraform workspace new dev
Created and switched to workspace "dev"!
$ terraform workspace new staging
Created and switched to workspace "staging"!
$ terraform workspace new prod
Created and switched to workspace "prod"!
Each workspace gets its own state file:
terraform.tfstate.d/
├── dev/
│ └── terraform.tfstate
├── staging/
│ └── terraform.tfstate
└── prod/
└── terraform.tfstate
How Isolation Works
workspace "dev" → creates: my-app-dev-bucket
workspace "staging" → creates: my-app-staging-bucket
workspace "prod" → creates: my-app-prod-bucket
Same config, different state, different resources.
Key Facts
| Fact | Detail |
|---|---|
| Default workspace | default — cannot be deleted |
| State isolation | Each workspace has its own state file |
| Configuration | Shared across all workspaces |
| Provider config | Shared across all workspaces |
| Switching | Instant — just changes which state file is used |
What’s Next?
Let’s learn the workspace commands.