“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" # 実際は workspace 名で分岐されることに注意
region = "ap-northeast-1"
}
}
# ワークスペース名をキーに含めるには、backend の機能や規約で設計(例: key に workspace を埋め込む命名規約)A 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"
}
}
}
# remote backend でも可。資格試験では、TFC/E workspace が state・実行・権限の単位である点を押さえる。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: 手動で実行
terraform plan
terraform apply
# TFC/E: VCS 連携(例)
# - main ブランチに PR -> Plan 作成
# - 承認者が Apply を承認 -> 実行
# API/手動トリガーも可(詳細は TFC/E の Run キュー挙動に依存)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
}
}
# 注意: terraform.workspace は CLI/TFC/E 双方で有効だが、命名衝突や容量制限を考慮することOn 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
# 現在のワークスペース確認(CLI)
terraform workspace show
# 変数の優先度確認(計画時の -var-file と環境変数)
terraform plan -var-file=vars/prod.tfvars
# TFC/E: 実行は UI/API が中心(CLI は cloud ブロック経由で送信)Associate / Pro
問題 1
Your organization wants strict separation of dev and prod, with RBAC and approval-gated Apply. Which design best matches Terraform's workspace concepts?
正解: 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
無料で問題を解いてみるNicheeLab 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...