“Workspace” in Terraform is a single word with two very different meanings. In the CLI it manages multiple states against the same config; in Cloud/Enterprise it is a fully independent execution unit.
Picking the wrong one when designing environment separation or permissions can lead to state collisions and permission gaps. This article walks through how to use each correctly, with diagrams, a comparison table, and command examples.
A CLI workspace switches the state file used against a single Terraform config in a single directory. In other words: one config, multiple states. State names are separated locally or on the backend.
A Terraform Cloud/Enterprise (TFC/E) workspace is an “execution unit” that bundles VCS integration, variable scope, run history, roles/permissions, and policy enforcement. Each workspace typically has its own state and execution pipeline.
Basic CLI workspace commands (works with local or any backend)
terraform workspace list
terraform workspace new dev
terraform workspace select dev
terraform plan -var-file=vars/dev.tfvars
terraform applyCLI workspaces are a fit when you want to apply the same config while switching state. A good example is lightweight environment separation (dev, test, qa) where the configs barely differ in behavior.
On the other hand, papering over environments with very different variables, provider settings, or module compositions using only CLI workspaces is risky. Human error around applying to the wrong workspace and complex conditional branches kill readability and breed review misses.
CLI workspaces and backend state naming (S3 backend example)
terraform {
backend "s3" {
bucket = "example-tfstate"
key = "projectA/terraform.tfstate" # note that the real path is namespaced by workspace name
region = "ap-northeast-1"
}
}
# To include the workspace name in the key, design it with backend features or a naming conventionA TFC/E workspace bundles everything you need to manage runs: VCS branch integration, variable and secret scope, plan/apply queues, roles and policies, plus state sharing and output references (run tasks and DRY design).
Cross-workspace integration is done safely via shared variables and output references (such as the remote state data source or TFC/E's built-in integrations). Avoid manually shuttling state files between workspaces.
Connecting to TFC/E (cloud block; variables managed in TFC/E)
terraform {
cloud {
organization = "your-org"
workspaces {
name = "projectA-prod"
}
}
}
# A remote backend works too. For the exam, remember that a TFC/E workspace is the unit of state, runs and permissions.Here are the differences that matter in day-to-day operations. On the exams in particular, confusing the CLI and TFC/E meanings of “workspace” is a very common trap.
The table below captures the points to remember for both design decisions and exam prep.
| Item | Terraform CLI workspace | Terraform Cloud/Enterprise workspace | Common exam trap |
|---|---|---|---|
| Concept | Switches state against the same config | Execution unit covering runs, permissions, and variables | The word “workspace” means different things in each |
| State file | Separated per workspace on the backend | One state per workspace by default | Do not treat CLI state and Cloud state as equivalent |
| Target config | Typically one directory, one config | Mapped to VCS branches or folders | Do not mix different configs into a single CLI workspace |
| Variables and secrets | Managed via tfvars and environment variables | Workspace-scoped Variables and Secrets | The CLI side has no secret protection or scoping |
| Run trigger | Manual plan and apply | VCS, manual, or API with queueing and approval flow | Cloud lets you design an Apply approval process |
| Permissions / isolation | Depends on local operations | Enforce RBAC and Policy as Code | CLI workspaces cannot enforce access control |
How workspaces and state relate in CLI vs TFC/E
Execution differences (CLI is manual; TFC/E uses a queue plus approvals)
# CLI: run it by hand
terraform plan
terraform apply
# TFC/E: VCS integration (example)
# - PR against main -> a plan is created
# - an approver approves the apply -> it runs
# API and manual triggers also work (details depend on the TFC/E run queue)The big question is what you split on. If the diff is large, split with directories or repos. If you need strong permissions and audit, split with TFC/E workspaces. If the diff is small and the same config works, switch lightly with CLI workspaces.
Set up naming conventions that bake the workspace name into resource names and backend keys, and pair them with pre-commit hooks, visible plan output, and an approval flow to prevent misapplies.
Naming convention example (reflecting the workspace name)
locals {
ws = terraform.workspace
}
resource "aws_s3_bucket" "app" {
bucket = "app-${local.ws}"
tags = {
env = local.ws
}
}
# Note: terraform.workspace works in both the CLI and TFC/E, but watch for name collisions and limitsOn the Associate and Pro exams, “CLI workspaces are a state-switching mechanism and do not provide full environment isolation or RBAC” shows up constantly. Also memorize that “TFC/E workspaces are the unit for runs, variables, and permissions, and include VCS integration and queueing.”
In production, watch out for ops flows getting tangled because the same word means different things. Even when using CLI and TFC/E together, make the responsibility split explicit: who applies and approves, where, and how.
Commonly used verification commands
# Check the current workspace (CLI)
terraform workspace show
# Check variable precedence (-var-file at plan time versus environment variables)
terraform plan -var-file=vars/prod.tfvars
# TFC/E: runs happen mainly in the UI/API (the CLI sends them via the cloud block)Associate / Pro
Question 1
Your organization wants strict separation of dev and prod, with RBAC and approval-gated Apply. Which design best matches Terraform's workspace concepts?
Correct answer: A
When RBAC and approval-gated Apply are requirements, the right move is to manage permissions and the run queue at the TFC/E workspace level. CLI workspaces are about switching state and offer neither approval flow nor RBAC.
Does the CLI workspace automatically affect resource naming?
No. The CLI workspace is purely a state-switching mechanism and does not change resource names automatically. If you need that behavior, design your config to reference terraform.workspace explicitly inside resource names.
How do I reference outputs across multiple TFC/E workspaces?
Use the remote state data source or TFC/E's built-in integration features. Avoid copying or overwriting state files directly — express dependencies through the official reference mechanisms instead.
What should I watch out for when migrating from CLI workspaces to TFC/E workspaces?
Plan the state import and migration steps carefully, and move variables and secrets into TFC/E Variables. Design the workspace split (dev/prod and so on), RBAC, and VCS integration up front, then document naming conventions and your plan/approve flow before cutting over.
Practice with certification-focused question sets
Try free questionsNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
HCL Syntax: Terraform's Configuration Language (2026)
HCL2 fundamentals for Terraform — blocks, attributes, expres...
Terraform Authoring & Operations Pro: Complete Guide (2026)
Tactics for the Terraform Pro exam — module authoring, works...
Terraform Providers: Plugin Management Fundamentals (2026)
Provider mechanics — required_providers, versions, mirrors, ...
Terraform Resource Blocks: Declarative Infra Units (2026)
Resource block fundamentals — addresses, references, common ...
Terraform Data Sources: Read-Only External Data (2026)
Data source basics — declaration, refresh behavior, dependen...