Terraform

Terraform Workspaces Explained: CLI vs Cloud for Ops and the Exam

2026-04-19
NicheeLab Editorial Team

“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.

Terminology: CLI and Cloud Workspaces Are Different Things

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.

  • CLI: switches state against a single config. Useful for small environment differences.
  • TFC/E: a fully managed execution unit built for organization and team workflows. Tightly coupled with VCS triggers, queueing, and permissions.

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 apply

CLI Workspaces: Where to Use Them and What to Avoid

CLI 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.

  • Good fit: small environment differences, namespace separation within the same region, PoCs.
  • Avoid: large environment diffs, production workloads needing strong access control, multi-region or multi-account setups.

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 を埋め込む命名規約)

Terraform Cloud/Enterprise Workspaces: The Unit of Execution and Governance

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.

  • VCS integration: standardize a review flow where push triggers plan and approval triggers apply.
  • RBAC and Policy: enforce team-level permissions and guardrails on a per-workspace basis.

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・実行・権限の単位である点を押さえる。

The Core Differences: Variables, Execution, Locking, Permissions (Comparison Table)

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.

  • Classic exam question: “CLI workspaces do not bundle multiple configs together.”
  • In practice: “If you need access control and audit, separate environments with TFC/E workspaces” is the baseline rule.
ItemTerraform CLI workspaceTerraform Cloud/Enterprise workspaceCommon exam trap
ConceptSwitches state against the same configExecution unit covering runs, permissions, and variablesThe word “workspace” means different things in each
State fileSeparated per workspace on the backendOne state per workspace by defaultDo not treat CLI state and Cloud state as equivalent
Target configTypically one directory, one configMapped to VCS branches or foldersDo not mix different configs into a single CLI workspace
Variables and secretsManaged via tfvars and environment variablesWorkspace-scoped Variables and SecretsThe CLI side has no secret protection or scoping
Run triggerManual plan and applyVCS, manual, or API with queueing and approval flowCloud lets you design an Apply approval process
Permissions / isolationDepends on local operationsEnforce RBAC and Policy as CodeCLI workspaces cannot enforce access control

How workspaces and state relate in CLI vs TFC/E

Shared config (./)CLI workspaceMultiple workspacesTFC/Eterraform workspaceSwitch between dev / prodworkspace: projectA-devworkspace: projectA-prodstate: devBackend switchstate: devIndependent + RBAC + VCSstate: prodBackend switchstate: prodIndependent + RBAC + VCSCLI switches state on a shared config; each TFC/E workspace is independent

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 キュー挙動に依存)

Environment Separation Strategy: Picking Between Directories, CLI Workspaces, and TFC/E Workspaces

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.

  • Large diff (very different region/account/provider settings): split by directory inside a monorepo, or by separate repos.
  • Medium diff (same structure but permissions and audit required): split TFC/E workspaces per environment.
  • Small diff (just tags or sizes): switch with CLI workspaces and tfvars.

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 双方で有効だが、命名衝突や容量制限を考慮すること

Exam Prep and Operational Pitfall Checklist

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.

  • Prevent misapplies: surface the workspace name, embed it in resource names, enforce protected branches and required reviews.
  • Avoid state collisions: lean on a lock-capable backend and the TFC/E run queue.

Commonly used verification commands

# 現在のワークスペース確認(CLI)
terraform workspace show

# 変数の優先度確認(計画時の -var-file と環境変数)
terraform plan -var-file=vars/prod.tfvars

# TFC/E: 実行は UI/API が中心(CLI は cloud ブロック経由で送信)

Check Your Understanding

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?

  1. Create separate TFC/E workspaces for dev and prod, and configure VCS integration plus an approval flow
  2. Switch between dev and prod with CLI workspaces, relying solely on code review for approval
  3. Put both dev and prod variable sets in a single TFC/E workspace and switch with variables
  4. Create CLI and TFC/E workspaces with the same name and allow Apply from either one

正解: 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.

Frequently Asked Questions

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.

Check what you learned with practice questions

Practice with certification-focused question sets

無料で問題を解いてみる
Author

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.


Related articles
Terraform

HCL Syntax: Terraform's Configuration Language (2026)

HCL2 fundamentals for Terraform — blocks, attributes, expres...

Terraform

Terraform Authoring & Operations Pro: Complete Guide (2026)

Tactics for the Terraform Pro exam — module authoring, works...

Terraform

Terraform Providers: Plugin Management Fundamentals (2026)

Provider mechanics — required_providers, versions, mirrors, ...

Terraform

Terraform Resource Blocks: Declarative Infra Units (2026)

Resource block fundamentals — addresses, references, common ...

Terraform

Terraform Data Sources: Read-Only External Data (2026)

Data source basics — declaration, refresh behavior, dependen...

Browse all Terraform articles (102)
© 2026 NicheeLab All rights reserved.