skip to content

HCP Terraform

HashiCorp's hosted Terraform service runs plans and applies remotely, keeps state in workspaces and gates runs on VCS events and policy. It is on the Associate exam, and interviewers ask what it adds to the CLI.

part ofTerraformread it →
on this pageshow

explore

questions

12

What does an HCP Terraform workspace hold, and how does that differ from a Terraform CLI workspace?

level: juniorimportance: must knowfreq 58%

answer

  1. two features, one shared name
  2. what a working directory used to hold
  3. state history and run history
  4. the unit teams get permissions on
  5. one directory, several state files

basics

~20 s

An HCP Terraform workspace holds what a working directory would: configuration, variables, credentials and state, plus state and run history and team permissions. A CLI workspace just gives one working directory an additional state file.

solid answer

~40 s

They share a name and little else. HCP Terraform manages infrastructure with workspaces instead of directories, so a workspace carries its configuration (from a linked repository or uploaded through the CLI or API), its variable values, its credentials as sensitive variables, and its state. It also keeps previous state versions and a record of its runs, and it is the unit you grant teams access on: Read, Plan, Write or Admin. A CLI workspace belongs to one working directory and isolates multiple state files there, so the code, the shell and the credentials stay the same. Terraform's own docs warn that CLI workspaces do not suit deployments needing separate credentials and access controls. HCP Terraform workspaces are also required: you cannot manage resources there without at least one.

go deeper

for a junior

Recall the four things a workspace holds in place of a directory: configuration, variables, credentials and state. Then say plainly that a CLI workspace only adds another state file to one directory.

for a middle

Explain how the cloud block connects the two: name ties a directory to one workspace, tags associate it with a matching set, and terraform workspace select then picks a full HCP Terraform workspace.

for a senior

Show you have seen the confusion cost something: a CLI-workspace layout migrated without rethinking names, or a team assuming separate state meant separate credentials. Name what the workspace actually isolates and what it leaves shared.

for a principal

Treat the workspace as the unit of permissions and run history, not only of state. That framing decides how an estate gets split, because a boundary that does not match team ownership forces over-broad grants.

## Two features that share a name Terraform has two different things called a workspace, and an interviewer asking this question wants to hear that you keep them apart. - An **HCP Terraform workspace** is an object in HashiCorp's HCP Terraform service, the hosted platform that runs Terraform and stores its results. - A **CLI workspace** is a feature of the `terraform` command that lets one working directory keep more than one state file. When you run Terraform locally, a persistent **working directory** holds the configuration, the state data and the variables. HCP Terraform replaces that directory with a workspace, and separate workspaces behave like completely separate working directories. ## What an HCP Terraform workspace holds | Component | Local Terraform | HCP Terraform workspace | |---|---|---| | Configuration | On disk | In a linked repository, or uploaded through the API or CLI | | Variable values | `.tfvars` files, CLI arguments, shell environment | In the workspace | | State | On disk or in a remote backend | In the workspace | | Credentials and secrets | Shell environment or prompts | In the workspace, as sensitive variables | On top of that, the service keeps data a directory never had: - **State versions:** backups of previous state files, useful for tracking changes and recovering from problems. - **Run history:** summaries, logs, what caused each run, and user comments. - **Settings:** the execution mode, the Terraform version, auto-apply and the working directory. - **Team access:** which teams can read, plan, apply or administer this workspace. - **A run queue:** each workspace processes its own runs in order. The configuration is tracked as a series of **configuration versions**, because the code changes over time, and each run is pinned to one of them. An HCP Terraform workspace manages a single state file, and it is required: you cannot manage resources in HCP Terraform without creating at least one. ## What a CLI workspace holds A CLI workspace belongs to a specific working directory and isolates multiple state files inside it. The configuration is the same code and the shell is the same shell. It has no variables, permissions or run history of its own, and the CLI does not make you create one, because every directory starts on a workspace named `default`. The Terraform language documentation states that CLI workspaces are not appropriate for deployments requiring separate credentials and access controls. ## Side by side | Question | HCP Terraform workspace | CLI workspace | |---|---|---| | Where it lives | In an HCP Terraform organization | Attached to one working directory | | Name scope | Unique within the organization | Local to that directory's backend | | Own variables | Yes | No | | Own credentials | Yes, as sensitive variables | No, whatever the shell holds | | Own permissions | Yes, granted per team | No | | Own run history | Yes, when HCP Terraform manages the runs | No | ## How the two meet in the `cloud` block The `cloud` block links a working directory to HCP Terraform workspaces, and this is where people mix the two up. - With `workspaces.name`, the directory is tied to one HCP Terraform workspace, and you cannot manage the workspace from the CLI. - With `workspaces.tags`, the directory is associated with every workspace matching all the tags, and `terraform workspace select` picks among them by full name. - When a directory with several CLI workspaces migrates, `terraform init` may prompt you to rename them, because HCP Terraform workspaces need unique names in the organization. A common pattern is `networking-prod-us-east`. So the CLI command survives, but the thing it selects is now a full HCP Terraform workspace, with its own variables and permissions. ## Mistakes to avoid in the answer 1. Saying an HCP Terraform workspace is a CLI workspace hosted remotely. It holds far more than state. 2. Saying `terraform workspace select` gives you a new set of credentials in a plain CLI setup. It switches the state file, and the credentials stay whatever the shell holds. 3. Forgetting credentials when you list the contents. Moving them off laptops is much of the practical value, as long as the run actually executes remotely.

  • Why might one configuration map to several HCP Terraform workspaces?
    The same code often manages several environments. A `cloud` block using `workspaces.tags` associates the directory with every workspace matching all the tags, so `networking-prod` and `networking-staging` share code while each keeps its own state, variables and permissions. You switch with `terraform workspace select` and the full workspace name.
  • Can you read a sensitive HCP Terraform workspace variable back after setting it?
    No. Marking a variable sensitive makes it write-only, so nobody can view it in the UI or read it through the Variables API, including the person who set it. Users with read and write access on variables can set a new value. The docs warn that even sensitive variables can sometimes end up in logs and state files.
  • Does a new HCP Terraform workspace created by `terraform init` come ready to use?
    Not necessarily. It has no Terraform or environment variables unless a global variable set applies, no VCS connection and no working directory, and its Terraform version is the latest release at creation. Check its settings in the UI before performing any runs.

  • An HCP Terraform workspace is just a CLI workspace hosted in the cloud.
  • A CLI workspace gives each environment its own credentials and permissions.
  • HCP Terraform workspaces are optional; you can run there without creating one.
  • One HCP Terraform workspace holds a separate current state for each environment.
  • A workspace variable is shared automatically with every workspace in the organization.
open as a page

On an HCP Terraform workspace connected to GitHub, what does a pull request's speculative plan do, and why can it never apply?

level: middleimportance: must knowfreq 50%

basics

~20 s

A speculative plan is a plan-only run HCP Terraform starts when a pull request opens or updates. It shows what the head branch would change against current state and cannot apply; the merge later queues a normal run that can.

open as a page

After a team adds HCP Terraform's `cloud` block and runs `terraform login`, where does `terraform plan` execute, and whose credentials does it use?

level: middleimportance: must knowfreq 52%

basics

~20 s

With Remote execution the plan runs on a disposable HCP Terraform worker, using the workspace's variables and credentials. The terraform login token only authenticates the CLI to HCP Terraform; cloud credentials in the laptop's shell are not sent.

open as a page

In an HCP Terraform run for a merged commit, which stages can stop the apply when a run task or a mandatory policy fails, and who can override?

level: seniorimportance: must knowfreq 46%

basics

~20 s

A mandatory run task can stop a run before the plan, after it or before the apply; a failed mandatory Sentinel or OPA policy stops it after the plan. Post-apply tasks stop nothing. Policy failures can pause for authorised override.

open as a page

In HCP Terraform, how do VCS-driven, CLI-driven and API-driven workflows differ in what starts a run and where its configuration comes from?

level: juniorimportance: should knowfreq 42%

basics

~20 s

VCS-driven runs start from webhooks and use a commit on the linked branch. CLI-driven runs start from terraform plan or apply and upload a local directory. API-driven runs start from your tooling, which uploads a tar.gz file.

open as a page

In HCP Terraform, how does a VCS trigger pattern differ from a run trigger between workspaces, and when would you use each?

level: middleimportance: should knowfreq 36%

basics

~20 s

A trigger pattern filters which changed repository files start a run in a VCS-connected workspace. A run trigger queues a run in one workspace after a source workspace applies successfully. One reacts to commits, the other to applies.

open as a page

In HCP Terraform, what do the Remote, Local and Agent execution modes change about where a run executes, and what does Local give up?

level: middleimportance: should knowfreq 46%

basics

~20 s

Remote runs on HCP Terraform's disposable VMs. Agent runs on agents you host, still managed by HCP Terraform. Local runs on your own machines with HCP Terraform storing only state, giving up workspace variables, policy enforcement, cost estimation and notifications.

open as a page

In HCP Terraform, when a workspace variable and two variable sets all define `region`, which value wins, and how do you force one?

level: middleimportance: should knowfreq 36%

basics

~20 s

A workspace-specific variable beats every ordinary variable set, and sets rank by ownership, then scope, then name order. To force a value, mark its variable set as priority, which outranks workspace variables and even command-line arguments.

open as a page

In HCP Terraform, how do dynamic provider credentials replace stored AWS keys, and why might a run's plan authenticate while its apply fails?

level: seniorimportance: should knowfreq 38%

basics

~20 s

HCP Terraform sends a signed OIDC token for each plan and apply; AWS verifies it and returns temporary credentials. The token's sub claim names the run phase, so a trust policy matching only plan rejects the apply.

open as a page

An HCP Terraform run has sat in Pending for an hour with no plan output: how do you find what is holding it and clear it safely?

level: seniorimportance: should knowfreq 41%

basics

~20 s

Check the workspace first: an earlier run paused for confirmation or a policy override holds the queue, as does a manual lock. If neither, check organization capacity. Clear the blocker through its owner; Force Cancel Run comes last.

open as a page

As a platform lead on HCP Terraform, how do you decide which controls belong in a run task, which in a policy set and which outside the service?

level: principalimportance: should knowfreq 30%

basics

~20 s

Put rules decided from run data in policy sets, checks needing an outside system in run tasks, and anything that must hold even when no run happens outside the service, such as cloud role trust and repository protection.

open as a page

A platform team moving a large estate to HCP Terraform expects about sixty workspaces across three projects: where do you draw those boundaries, and which team roles do you grant?

level: principalimportance: should knowfreq 38%

basics

~20 s

Draw workspaces around blast radius, rate of change and team ownership; draw projects around who needs which access. Grant roles at project level, keep project admins few, and remember permissions are additive: a narrower workspace role cannot subtract.

open as a page