Terraform State Backends and Workspaces: Local vs Remote, CLI vs HCP Terraform, and Which One a Question Wants
Terraform uses the word "workspace" for two different things, and it stores state in two very different kinds of place. Exam questions use that overlap on purpose: an option that would be right for an HCP Terraform workspace is wrong for a CLI workspace, and a fix that works for a remote backend does nothing for local state. The word workspace appears in the question or options of 103 of the 518 Terraform questions in this question bank, across both exams. This comparison sorts the four ideas apart and lists the clues that tell you which one a question is about.
Concept comparison · TF-TA004 and TF-IEP002

The short answer
A backend decides where state lives. Local means a file in the working directory; remote means a shared store such as an S3 bucket or HCP Terraform, usually with locking, encryption and access control. A CLI workspace is just another state file under the same configuration, backend and credentials. An HCP Terraform workspace is a full replacement for a working directory, with its own state versions, variables, credentials, run history and permissions. When a question is about isolation, access control or separate credentials, a CLI workspace is almost never the answer.
Local versus remote state
| Local backend | Remote backend (for example s3) or HCP Terraform | |
|---|---|---|
| Where state is | terraform.tfstate in the working directory, plus a .backup copy | A shared object or workspace that everyone reads |
| Locking | A file lock on that one machine | Shared locking, where the backend supports it (s3 needs use_lockfile = true; HCP Terraform locks per workspace) |
| Secrets in state | Plain JSON on a laptop | Encryption and access control are available; state must still be treated as secret |
| Recovery | The single backup file | Bucket versioning, or state versions in HCP Terraform |
| Good for | One person learning | Any team |
Two rules that show up as wrong answers: Git is not a state store (no locking, no control over who reads the secrets inside), and a backend block cannot refer to named values such as input variables or locals. Per-environment values go in through partial configuration: terraform init -backend-config=prod.s3.tfbackend. To connect to HCP Terraform you normally write a cloud block instead of a backend block; the two are mutually exclusive, so a configuration has one or the other, never both.
Locking is not backup
A lock stops two runs from writing the same state at once: the second run cannot acquire the lock and fails. Three tools adjust this. -lock-timeout=10m makes a run wait and retry (the default is 0s, so it fails at once). -lock=false removes the protection and is rarely right. terraform force-unlock LOCK_ID clears a stale lock left by a killed run, and is safe only when you are sure nobody holds it.
For the s3 backend, the current answer is a lock file next to the state object (use_lockfile = true); locking with a DynamoDB table is deprecated. Terraform needs s3:DeleteObject on the lock file to release the lock, so "lock still held after a successful run" points to permissions. Keep the three protections apart: locking serializes writers, encrypt protects data at rest, and only bucket versioning lets you restore an older state after someone overwrote it.
Going deeper: -migrate-state versus -reconfigure, and the empty-state incident
Terraform remembers the initialized backend in the .terraform directory. When the backend block changes, terraform init stops until you say what should happen to the state. -migrate-state copies the existing state to the new location. -reconfigure ignores the old configuration and copies nothing, so the new location starts empty and the next plan proposes to create every resource that already exists. That is the classic production incident: someone picks -reconfigure to silence the error. Moving from an s3 backend to HCP Terraform follows the same path: swap in the cloud block, run init, and accept the offer to copy the state. Back up the state file first in every case.
CLI workspaces versus HCP Terraform workspaces
| CLI workspace | HCP Terraform workspace | |
|---|---|---|
| What it is | A separate state instance in one working directory; the documentation calls it technically equivalent to renaming the state file | A managed unit with its own state versions, variables, credentials, runs and team permissions |
| Configuration and backend | Shared by all workspaces | Per workspace |
| Credentials and access | The same for every workspace, so not an access boundary | Set per workspace (Read, Plan, Write, Admin) or per project (Read, Write, Maintain, Admin) |
| Commands | terraform workspace new/select/list/show; terraform.workspace in code | UI, API, or a cloud block naming one workspace or selecting several by tags |
| Documented fit | A short-lived parallel copy to test a change, such as one per feature branch | Each environment or component of a team's infrastructure |
The two meet in one place. With cloud { workspaces { tags = [...] } }, the CLI's terraform workspace list and select operate on the HCP Terraform workspaces that carry those tags. name and tags cannot be combined, and each run still targets exactly one workspace.
Beginner tip: in any local test folder with the default local backend, run terraform workspace new test, apply something small, and then list the folder. You will find the new workspace's state in its own file under terraform.tfstate.d/test/, next to the default terraform.tfstate, with the same code and the same credentials. Seeing that a CLI workspace is only a second file makes the "is this an isolation boundary?" questions easy.
Which one does the question want?
- "Dev credentials can select prod and apply" or "auditors require separate access per environment" → not CLI workspaces. Use separate root modules per environment, each with its own backend, or separate HCP Terraform workspaces.
- "A throwaway copy to test a change without a new directory or backend" → a CLI workspace.
- "Variables, credentials and run history per environment, with team permissions" → HCP Terraform workspaces, grouped in projects.
- "Two engineers overwrote each other's changes" → a remote backend with locking.
- "Restore state after a bad
state push" → bucket versioning or HCP Terraform state versions, not locking. - "A fresh clone plans to create everything and
state listis empty" → checkterraform workspace show; a new clone starts indefault. Do not apply that plan.
Going deeper: how a prod consumer quietly reads dev data
With a backend that supports CLI workspaces, each workspace keeps its state under a separate key. The terraform_remote_state data source reads only the producer's root-module outputs, and its optional workspace argument picks which of the producer's workspaces to read. It does not follow the consumer's own workspace: a consumer running in prod reads the producer's prod outputs only if it sets workspace = terraform.workspace (or another explicit name) or points at the right key. Nothing errors. A related trap: terraform workspace select dev followed by -var-file=prod.tfvars plans production sizes against dev state, because nothing ties a variable file to a workspace. Both are reasons why the documentation recommends separate configurations for environments that need strong separation.
Separate root modules, or separate HCP Terraform workspaces
HCP Terraform workspaces, grouped in projects
A remote backend with locking
Bucket versioning or HCP Terraform state versions
A throwaway copy to test a change in the same directory: a CLI workspace
Practise
Practise in the question bank: every question explains each option, right and wrong. Start with the domain you just studied, then take a timed mock exam.
- TF-TA004 exam page · All 326 TF-TA004 questions · Timed mock exam · 18-day study plan
- By domain (TF-TA004): Infrastructure as Code (IaC) with Terraform · Terraform fundamentals · Core Terraform workflow · Terraform configuration · Terraform modules · Terraform state management · Maintain infrastructure with Terraform · HCP Terraform
- TF-IEP002 exam page · All 312 TF-IEP002 questions · Timed mock exam · 20-day study plan
- By domain (TF-IEP002): Terraform configuration · State management and upgrades · Infrastructure workflow and lifecycle · CI/CD and deployment · Security, secrets and compliance · Modules and the registry · HCP Terraform operations
Based on HashiCorp's Terraform documentation for backends, state locking and workspaces, and on the exam content for TF-TA004 and TF-IEP002. Backend options change between Terraform versions; check the documentation for the version you are tested on.