HCP Terraform: Workspaces, Collaboration, and Governance
HCP Terraform is HashiCorp's managed platform for running Terraform as a team: it executes plans and applies remotely, stores, versions and locks state for you, keeps variables and secrets in the workspace, and layers collaboration and governance on top of the core workflow — VCS-driven pull-request plans, team and project permissions, a private registry, Sentinel and OPA policy-as-code, run tasks and cost estimation. It was formerly named Terraform Cloud, and the 004 exam uses the new name throughout; objective 8 is new in this exam version. You connect a working directory to it with terraform login (or a TF_TOKEN_ environment variable in automation), a cloud block naming your organization and workspace, and terraform init. The highest-yield distinction to master: an HCP Terraform workspace is a full unit of infrastructure management — its own state, variables, run history and permissions — while a CLI workspace is merely an alternate state file for one configuration. This lesson covers the platform, the integration, workspaces and projects, and every collaboration and governance feature objective 8 names.
On this page9 sections
- What is HCP Terraform?
- Connecting the CLI: terraform login and the cloud block
- How HCP Terraform creates infrastructure: remote runs
- HCP Terraform workspaces vs CLI workspaces
- Projects: organizing workspaces
- Remote state, locking, and secure variable storage
- Sharing data between workspaces: remote state sharing, tfe_outputs, and run triggers
- Collaboration: VCS integration, teams, and the private registry
- Governance: Sentinel policies, run tasks, and cost estimation
- Explain what HCP Terraform is and how it differs from running Terraform locally with the CLI alone
- Configure the HCP Terraform integration with terraform login or TF_TOKEN_ variables, the cloud block and terraform init
- Choose between the CLI-driven, VCS-driven and API-driven run workflows and the remote, local and agent execution modes
- Distinguish HCP Terraform workspaces from CLI workspaces, organize workspaces into projects and assign project and workspace permissions
- Describe remote state, sensitive variables, variable sets and the order in which variable values take precedence
- Share data between workspaces with remote state sharing, tfe_outputs and run triggers
- Describe collaboration features: VCS integration, auto-apply, team access and the private registry
- Describe governance features: Sentinel and OPA policy sets and their enforcement levels, run task stages and cost estimation
What is HCP Terraform?
HCP Terraform is HashiCorp's managed application for running Terraform collaboratively — a SaaS platform (hosted at app.terraform.io) that executes Terraform runs remotely, stores state, manages variables and secrets, and adds team and governance features on top of the open-source CLI. It was formerly called Terraform Cloud; HashiCorp renamed it when it joined the HashiCorp Cloud Platform family, and the 004 exam uses the new name. The self-hosted version of the same application, installed in your own environment, is Terraform Enterprise.
Why it exists: the core CLI workflow works well for one person, but a team hits problems immediately — where does state live, who is applying right now, how are credentials shared, and who approved this change? Running Terraform locally means every engineer needs cloud credentials on their laptop, and nothing stops two people applying at once. HCP Terraform answers all of these in one place: state is stored centrally and locked automatically during runs, credentials live in the workspace rather than on laptops, runs happen in a consistent remote environment, and every plan and apply is recorded with who triggered and who approved it.
You still write the same HCL and use the same terraform CLI. The difference is where runs execute and where state lives. Keep the naming straight for the exam: HCP Terraform is the managed platform (formerly Terraform Cloud), Terraform Enterprise is self-hosted, and Terraform Community Edition is the open-source CLI on its own.
Connecting the CLI: terraform login and the cloud block
You connect a working directory to HCP Terraform in three steps: authenticate the CLI, add a cloud block to the configuration, and run terraform init. For interactive use, terraform login opens a browser to generate a user API token and stores it locally in credentials.tfrc.json (under ~/.terraform.d/), so subsequent commands can call the HCP Terraform API. By default it targets app.terraform.io; pass a hostname to log in to a Terraform Enterprise instance instead.
$ terraform login Terraform will request an API token for app.terraform.io using your browser. ... Success! Terraform has obtained and saved an API token.
The cloud block lives inside the top-level terraform block and names your organization and the workspace(s) this configuration maps to — either one workspace by name, or a set of workspaces selected by tags:
terraform {
cloud {
organization = "acme-corp"
workspaces {
name = "networking-prod"
}
}
}With tags instead of name, terraform workspace select chooses among the matching HCP Terraform workspaces from the CLI. terraform init is mandatory after adding or changing a cloud (or backend) block: until it runs, terraform plan and terraform apply stop with an error saying the working directory needs to be initialized. If you have existing local state, init offers to migrate it into the HCP Terraform workspace.
Non-interactive authentication and workspace selection
In CI there is no browser, so terraform login does not fit. Instead supply the token through an environment variable named TF_TOKEN_ plus the hostname, with dots written as underscores — TF_TOKEN_app_terraform_io for HCP Terraform — holding a team or user API token kept as a pipeline secret. The cloud block also accepts a token argument, but writing a token into configuration commits a secret to the repository, so HashiCorp recommends against it. Other environment variables fill in the block without editing the configuration: TF_CLOUD_ORGANIZATION and TF_CLOUD_HOSTNAME, and TF_WORKSPACE, which selects the workspace to use — handy when the block selects workspaces by tags and the pipeline must target one of them.
Exam trap: the cloud block is the recommended replacement for the older remote backend (it shipped in Terraform 1.1 and is the standard method in Terraform 1.12). A configuration cannot contain both a backend block and a cloud block — the cloud block is not a backend, though it plays the same role of deciding where state lives.
How HCP Terraform creates infrastructure: remote runs
HCP Terraform creates infrastructure through runs: a plan, any policy checks, run tasks and cost estimation, then an apply. In the default remote execution mode these execute on HashiCorp-managed run environments instead of your machine, using variables and credentials stored in the workspace. When you run terraform plan or terraform apply in a directory with a cloud block, the CLI uploads the configuration, the run executes remotely, and the output streams back to your terminal. Applies can be confirmed from the terminal or from the web UI.
Three run workflows
| Workflow | Who starts the run | Fits when |
|---|---|---|
| CLI-driven | An engineer runs terraform plan / terraform apply locally; execution is remote | You want the familiar CLI with remote state, variables and policy enforcement |
| VCS-driven | Commits and merges to the workspace's tracked branch; pull requests get speculative plans | The repository is the source of truth and changes go through review |
| API-driven | Another tool calls the HCP Terraform API: it uploads a configuration version (a packaged copy of the configuration files) and creates a run | A CI system or in-house tool orchestrates runs; the caller needs only an API token — no Terraform binary and no VCS connection |
CLI runs against a VCS-connected workspace, and saved plans
A workspace connected to a repository treats the repository as the source of truth. From a laptop with a cloud block pointing at it, terraform plan still works — it runs remotely as a speculative plan (plan-only, never applicable) and streams its output — but terraform apply is refused; changes must be merged through the repository. On CLI-driven workspaces, a plain terraform plan is also speculative: it previews, and a later terraform apply makes a fresh plan. To review a plan now and apply exactly that plan later, use a saved plan (Terraform 1.6 and later): terraform plan -out=FILE creates a saved plan run in the workspace, and terraform apply FILE applies that run without planning again.
Execution modes
| Mode | Where plans and applies run | What to remember |
|---|---|---|
| Remote (default) | HCP Terraform's managed run environment | Uses workspace variables and variable sets; policies, run tasks and cost estimation apply |
| Local | The machine where the engineer runs the CLI | The workspace only stores (and locks) state. HCP Terraform does not evaluate workspace variables or variable sets, so values and credentials must come from the local environment; runs are not visible or governed in HCP Terraform |
| Agent | Self-hosted HCP Terraform agents in an agent pool you run, for example inside a private data centre | Agents poll HCP Terraform over outbound connections, so isolated networks need no inbound access; runs remain full HCP Terraform runs with state, variables and policy enforcement |
HCP Terraform workspaces vs CLI workspaces
They share a name but are different things, and this is one of the most commonly tested traps in objective 8. A CLI workspace is just an alternate state file for a single configuration in a single working directory — created with terraform workspace new, it changes nothing but which state Terraform reads and writes. An HCP Terraform workspace is a complete unit of infrastructure management: it owns its state and its variables, credentials, run history, VCS connection, permissions, and notification settings.
| Aspect | CLI workspaces | HCP Terraform workspaces |
|---|---|---|
| What it is | An alternate state file for one configuration | State, variables, runs, settings, and permissions in one unit |
| Created by | terraform workspace new dev | Web UI, API, or terraform init with a cloud block |
| Variables | Not stored — you supply values yourself | Stored per workspace, plus shared variable sets |
| Run history | None | Full audit trail of plans and applies |
| Access control | None | Team permissions per workspace and project |
| State locking | Depends on the backend | Automatic during every run |
The standard pattern on HCP Terraform is one workspace per environment per component — for example networking-dev, networking-staging, networking-prod — often all linked to the same repository but with different variables and permissions. This replaces the CLI-workspace habit of switching state files under one directory, and it is what the tags form of the cloud block is designed for: tag all three workspaces networking and select between them with terraform workspace select.
Projects: organizing workspaces
Projects are how you organize workspaces inside an HCP Terraform organization: a project is a group of related workspaces, typically owned by one team or covering one application or business area. Every workspace belongs to exactly one project (organizations start with a Default Project), and the hierarchy is organization → projects → workspaces.
Projects matter because settings scoped to a project reach every workspace inside it, present and future. You can scope team access, variable sets and policy sets to a project instead of maintaining them workspace by workspace.
Project roles
Team access to a project uses fixed roles (custom permissions are also available):
| Project role | What it grants |
|---|---|
| Read | View the project and read its workspaces |
| Write | Write access on every workspace in the project: queue, approve and apply runs, lock workspaces, edit variables — but not manage workspace settings or the project |
| Maintain | Admin access on the project's workspaces, including creating them and managing their settings and variables — but not changing project settings, deleting the project or managing which teams can access it |
| Admin | Everything, including project settings, team access to the project and deleting it |
For the exam, keep the two organizing layers distinct: workspaces separate state and runs (one per environment per component), while projects group workspaces for ownership, access control and shared configuration. Pick the least-privileged role that covers the task.
Remote state, locking, and secure variable storage
Every HCP Terraform workspace stores its state remotely, encrypted, and versioned — you can inspect previous state versions and see which run produced each one. State is locked automatically for the duration of every run, so two concurrent applies against the same workspace are impossible; there is nothing to configure, unlike DIY backends where locking support varies. Access to state follows workspace permissions; sharing state with other workspaces is covered in the next section.
Variables are stored on the workspace in two categories: Terraform variables (values for the configuration's input variables, equivalent to a .tfvars file) and environment variables (shell variables set in the run environment). Provider credentials such as AWS_ACCESS_KEY_ID or ARM_CLIENT_SECRET belong in the environment category: the provider reads them from the environment, so storing them as Terraform variables does nothing unless the configuration declares matching input variables.
Any variable can be marked sensitive. That makes it write-only for people: the value is never displayed again in the UI or returned by the API, but it is still passed in full to every run. Sensitive is not a log scrubber — if the configuration routes the value into an output or a resource argument, Terraform can still show it in run output and it is stored in state. This is how teams keep secrets off laptops: engineers trigger runs, but the credentials exist only in the workspace.
Variable sets solve the reuse problem: define a collection of variables once (for example, shared cloud credentials or proxy settings) and apply it to specific workspaces, to projects, or globally to every workspace in the organization. Changing the set updates every workspace that uses it.
Which value wins
When the same variable key is set in several places, HCP Terraform applies this order, highest first:
- Priority variable sets — a set marked priority overrides every other value for the same key, including
-varand-var-filevalues given on the CLI. - Values passed on the command line in a CLI-driven run (
-var,-var-file). - Local environment variables prefixed with
TF_VAR_in a CLI-driven run. - Workspace-specific variables.
- Variable sets (not priority) — a set applied to the workspace directly beats a project-scoped set, which beats a global set.
*.auto.tfvarsfiles, thenterraform.tfvars, from the configuration.
So workspace-specific variables override variable sets; priority sets are the tool an organization uses when a value must not be overridden anywhere below it.
Collaboration: VCS integration, teams, and the private registry
Collaboration in HCP Terraform is built on three features. First, VCS integration: connect a workspace to a repository (GitHub, GitLab, Bitbucket, Azure DevOps) and the platform becomes the automation layer for a GitOps-style flow. Opening a pull request triggers a speculative plan whose result is posted to the PR as a status check, so reviewers see exactly what the change would do before merging; speculative plans are plan-only and can never be applied. Merging to the tracked branch queues a standard plan-and-apply run.
Whether that run applies on its own is the workspace's auto-apply setting. With auto-apply off (the default), every plan that has changes stops and waits for a user with permission to confirm the apply — a built-in human review step. With auto-apply on, a successful plan applies without confirmation. (Runs queued by run triggers use the separate Auto-apply run triggers setting described above.)
Second, team-based access management. Users belong to an organization and are grouped into teams; teams are granted roles on projects (see Projects above) and permission sets on individual workspaces. The fixed workspace permission sets are:
- Read — view runs, state versions and settings.
- Plan — everything in read, plus queue plans; cannot apply, so it cannot change infrastructure.
- Write — plan plus approve and apply runs, lock the workspace and edit variables.
- Admin — write plus manage workspace settings, team access and deletion.
Custom permissions are available for finer control, and members of the built-in owners team manage the organization itself. This answers the governance question the CLI cannot: who is allowed to apply changes to production?
Third, the private registry. Each organization gets its own registry for sharing modules and providers internally, with the same versioned, documented experience as the public Terraform Registry. Private modules are referenced with a hostname-qualified source of the form <HOSTNAME>/<ORGANIZATION>/<NAME>/<PROVIDER>:
module "vpc" {
source = "app.terraform.io/acme-corp/vpc/aws"
version = "2.1.0"
}The private registry is how platform teams publish approved, reusable building blocks — including no-code modules that let non-Terraform users deploy curated infrastructure from the UI.
Governance: Sentinel policies, run tasks, and cost estimation
Governance features let an organization enforce rules on every run rather than trusting reviewers to catch violations. HCP Terraform supports two policy-as-code frameworks: Sentinel, HashiCorp's own language, and Open Policy Agent (OPA), whose policies are written in Rego. Policies are evaluated automatically after the plan and before the apply, and can fail a run that violates a rule — for example, requiring tags on every resource, blocking 0.0.0.0/0 ingress or restricting instance types.
Policy sets
Policies are grouped into policy sets, and the set decides where they apply: globally (every workspace in the organization, including ones created later), to specific projects, to specific workspaces, or to workspaces carrying specific tags. A global set can exclude particular projects, workspaces or tagged workspaces, which avoids per-workspace upkeep. Each policy set holds policies for one framework only — Sentinel or OPA — so a team using both creates separate sets; several policy sets can apply to the same workspace.
Enforcement levels
| Framework | Level | When a policy fails |
|---|---|---|
| Sentinel | Advisory | Reported as a warning; the run carries on |
| Sentinel | Soft mandatory | The run stops, but a user with the Manage Policy Overrides permission can override and continue |
| Sentinel | Hard mandatory | The run stops; nobody can override |
| OPA | Advisory | Reported as a warning; the run carries on |
| OPA | Mandatory | The run stops, but a user with the Manage Policy Overrides permission can override it (OPA has no un-overridable level) |
Run tasks
Run tasks extend governance to third-party tools: HCP Terraform calls an external service — a security scanner, a compliance checker — at a chosen stage of the run and waits for its pass/fail result. The four stages are pre-plan (before Terraform builds the plan, so the service can check the configuration files and stop the run early), post-plan (the service can inspect the plan), pre-apply (just before applying) and post-apply (after resources change). Each run task attached to a workspace has an enforcement level: advisory (a failure is a warning) or mandatory (a failure stops the run).
Cost estimation
Cost estimation is a built-in run phase after the plan: for supported AWS, Azure and Google Cloud resources, HCP Terraform estimates the monthly cost of the planned infrastructure and the delta against current cost, shown in the run before apply. Sentinel policies can read the cost estimate — enabling rules like "fail any run that raises monthly spend by more than 20 percent" — but only in legacy policy checks (Sentinel only), not in the newer policy evaluations (Sentinel and OPA), which cannot read cost estimates.
Tip. The 004 exam is the first Terraform Associate version with a dedicated HCP Terraform objective, so expect several questions from this domain. High-yield items: the CLI-workspace vs HCP-workspace distinction, terraform login versus TF_TOKEN_ variables, the cloud block and the required terraform init, the three run workflows and three execution modes (including what local mode does not do), auto-apply and run triggers, variable categories, sensitive values and precedence, project roles and workspace permission sets, cross-workspace output sharing, and the Sentinel and OPA enforcement levels, policy-set scoping and run task stages. Scenario questions describe a team problem — shared secrets, review before apply, private networks, cost control, least privilege — and ask which feature or setting solves it.
- HCP Terraform (formerly Terraform Cloud) is HashiCorp's managed platform: remote runs, versioned remote state with automatic locking, stored variables, and team governance; Terraform Enterprise is the self-hosted version.
- Integration: authenticate (terraform login interactively, TF_TOKEN_app_terraform_io in CI — never a token in the cloud block), add a cloud block (organization + workspace name or tags), then terraform init, which is required before plan or apply and can migrate local state.
- Run workflows: CLI-driven, VCS-driven (merges run plan-and-apply, pull requests get speculative plans) and API-driven (upload a configuration version, no Terraform binary or VCS needed). CLI apply is refused on VCS-connected workspaces; saved plans (plan -out, apply FILE) apply exactly the reviewed plan.
- Execution modes: remote (default), local (runs on your machine; the workspace only stores state and does not supply its variables) and agent (self-hosted agents inside private networks, outbound connections only).
- An HCP Terraform workspace owns state, variables, run history and permissions — a CLI workspace is only an alternate state file. Projects group workspaces so team access, variable sets and policy sets apply to all of them; project roles are Read, Write, Maintain and Admin.
- Credentials go in environment variables; sensitive makes a value write-only for people but still passes it to runs and does not scrub it from output or state. Precedence: priority variable sets > CLI -var > workspace variables > project sets > global sets > tfvars files.
- Workspaces share outputs via remote state sharing (governs terraform_remote_state, which needs the full snapshot) or tfe_outputs (outputs only, governed by its token). Run triggers queue a downstream run after a source apply; they auto-apply only with the separate Auto-apply run triggers setting.
- Policy sets hold Sentinel or OPA policies (one framework per set), scoped globally (with exclusions), to projects or to workspaces. Sentinel: advisory, soft mandatory (overridable), hard mandatory. OPA: advisory, mandatory (overridable with Manage Policy Overrides). Run tasks run at pre-plan, post-plan, pre-apply or post-apply as advisory or mandatory; cost estimation shows monthly cost and delta before apply.
Frequently asked questions
Is HCP Terraform the same thing as Terraform Cloud?
Yes. Terraform Cloud was renamed HCP Terraform when it became part of the HashiCorp Cloud Platform. It is the same managed application at app.terraform.io, and the 004 exam uses the HCP Terraform name. The self-hosted version remains Terraform Enterprise.
What is the difference between a CLI workspace and an HCP Terraform workspace?
A CLI workspace (terraform workspace new) is just an additional state file for one configuration in one working directory — nothing else changes. An HCP Terraform workspace is a full management unit with its own state, variables, credentials, run history, VCS connection, and team permissions. The exam tests this distinction directly.
Should I use the cloud block or the remote backend?
Use the cloud block. It has been the recommended way to connect a configuration to HCP Terraform since Terraform 1.1, replacing the older backend "remote" configuration. A configuration cannot declare both a cloud block and a backend block, and after adding or changing either you must run terraform init before plan or apply will work.
How do I authenticate Terraform to HCP Terraform in a CI pipeline?
Set an environment variable named TF_TOKEN_ followed by the hostname with dots replaced by underscores — TF_TOKEN_app_terraform_io for HCP Terraform — to a team or user API token stored as a pipeline secret. terraform login is meant for interactive use, and putting a token in the cloud block's token argument would commit a secret to the repository. TF_WORKSPACE can select the workspace without editing the configuration.
Does marking an HCP Terraform variable as sensitive hide it everywhere?
No. A sensitive workspace variable is write-only for people: the UI and API never show its value again, but it is still passed in full to every run. If the configuration sends the value into an output or a resource argument, it can still appear in run output and is stored in state. Mark the related outputs and variables sensitive in the configuration too.
What happens if a Sentinel or OPA policy fails during a run?
It depends on the enforcement level. Advisory failures are logged as warnings and the run continues. A Sentinel soft-mandatory or OPA mandatory failure stops the run, but a user with the Manage Policy Overrides permission can override it. A Sentinel hard-mandatory failure stops the run with no override. Policies are evaluated after the plan and before the apply.
How can one HCP Terraform workspace use another workspace's outputs?
Either with the terraform_remote_state data source, which requires the source workspace's remote state sharing setting to include the reader and grants access to the full state snapshot, or with the tfe provider's tfe_outputs data source, which reads outputs only and depends on its API token's permissions rather than on the sharing setting. HashiCorp recommends tfe_outputs as the more secure choice. A run trigger can also queue the reader's run whenever the source applies.
Can HCP Terraform manage infrastructure in a private network it cannot reach?
Yes, with agent execution mode. You deploy HCP Terraform agents inside the private environment; they poll HCP Terraform for work over outbound connections, so no inbound access is required, and runs keep HCP Terraform state, variables and policy enforcement. Local execution mode also reaches private networks, but runs then happen on an engineer's machine and the workspace only stores state.
Source
This lesson covers the "HCP Terraform" domain of the official Terraform 004 exam guide. Vendors revise their guides — check the source for the current version.
- HashiCorp Terraform Associate certification page — HashiCorp
Sign up free to mark lessons complete, bookmark topics and track your exam readiness.