SaveMyCert
Log in
5 of 5 free questions left today·for unlimited practice
HCP Terraform

HCP Terraform: Workspaces, Collaboration, and Governance

12 min readTerraform 004 · HCP TerraformUpdated

HCP Terraform is HashiCorp's managed platform for running Terraform as a team: it executes plans and applies remotely, stores and locks state for you, keeps variables and secrets in the workspace, and layers collaboration and governance — VCS-driven pull-request plans, role-based access, a private registry, Sentinel policy-as-code, run tasks, and cost estimation — on top of the core workflow. 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 and a cloud block naming your organization and workspace. 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, and every collaboration and governance feature objective 8 names.

What you’ll learn
  • 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 and the cloud block, and trigger remote runs via the CLI, VCS, or API
  • Distinguish HCP Terraform workspaces from CLI workspaces, and organize workspaces into projects
  • Describe remote state storage, automatic state locking, and secure variable storage including variable sets and sensitive values
  • Describe collaboration features: VCS integration with pull-request plans, team-based access control, and the private registry
  • Describe governance features: Sentinel policy-as-code and its enforcement levels, run tasks, 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 two steps: authenticate the CLI with terraform login, then add a cloud block to the configuration. 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. After adding the block, run terraform init; if you have existing local state, init offers to migrate it into the HCP Terraform workspace. You can also configure the integration through environment variables such as TF_CLOUD_ORGANIZATION and TF_WORKSPACE, which is useful in CI.

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 remote runs: plan and apply execute on HashiCorp-managed run environments instead of your machine, using credentials stored in the workspace. When you run terraform plan in a directory with a cloud block, the CLI uploads the configuration, the run executes remotely, and the output streams back to your terminal — this is the CLI-driven workflow. Applies can be confirmed from the terminal or from the web UI.

There are three ways to trigger runs, and the exam expects you to know all three:

  • CLI-driventerraform plan / terraform apply from your terminal, executed remotely.
  • VCS-driven — the workspace is linked to a repository branch; a merge triggers a plan-and-apply run, and pull requests get automatic speculative plans (plan-only runs that can never be applied) posted as status checks.
  • API-driven — external systems (CI pipelines, custom tooling) create runs via the HCP Terraform API using API tokens.

Each workspace also has an execution mode. Remote (the default) runs plans and applies on HCP Terraform's infrastructure. Local executes runs on your own machine while still using the workspace for state storage — useful when runs need access to a private network. Agent mode runs operations on self-hosted HCP Terraform agents you deploy inside private environments, so HCP Terraform can manage isolated infrastructure without inbound network access.

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.

AspectCLI workspacesHCP Terraform workspaces
What it isAn alternate state file for one configurationState, variables, runs, settings, and permissions in one unit
Created byterraform workspace new devWeb UI, API, or terraform init with a cloud block
VariablesNot stored — you supply values yourselfStored per workspace, plus shared variable sets
Run historyNoneFull audit trail of plans and applies
Access controlNoneTeam permissions per workspace and project
State lockingDepends on the backendAutomatic 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 for two practical reasons. First, scoped permissions: you can grant a team access at the project level and it applies to every workspace inside, present and future — far more maintainable than granting workspace-by-workspace. Second, scoped variable sets: a variable set can be applied to a project so that all of its workspaces share the same credentials or common settings automatically.

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.

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, and workspaces can explicitly share their state outputs with other workspaces for cross-workspace consumption.

Variables are stored on the workspace in two kinds: Terraform variables (input variable values, equivalent to a .tfvars file) and environment variables (shell variables for the run environment — this is where provider credentials such as AWS_ACCESS_KEY_ID or ARM_CLIENT_SECRET usually go). Any variable can be marked sensitive: its value is write-only, never displayed again in the UI or API, and not revealed in run logs. This is how teams keep secrets off laptops entirely — engineers trigger runs, but the credentials only exist in the workspace.

Variable sets solve the reuse problem: define a collection of variables once (for example, cloud credentials for a shared account) and apply it to specific workspaces, to projects, or globally to every workspace in the organization. When the same variable is defined in multiple places, the more specific scope wins — a variable set on the workspace itself overrides one inherited from the project or organization.

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; merging to the tracked branch triggers the real run. Speculative plans are plan-only and can never be applied.

Second, team-based access management. Users belong to an organization and are grouped into teams; teams are granted permissions on projects and workspaces. The fixed workspace permission sets are read (view runs and settings), plan (queue plans), write (approve and apply runs, edit variables), and admin (manage settings and team access) — with custom permissions available for finer control. 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:

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. The centerpiece is Sentinel, HashiCorp's policy-as-code framework: policies are written as code, versioned, grouped into policy sets attached to workspaces, and evaluated automatically between the plan and apply phases of a run. A Sentinel policy can inspect the plan and fail the run if it violates a rule — for example, requiring specific tags on every resource, blocking 0.0.0.0/0 ingress rules, or restricting instance types.

Each Sentinel policy has one of three enforcement levels, a frequent exam question:

  • Advisory — a failure is logged as a warning; the run proceeds.
  • Soft mandatory — a failure blocks the run, but an authorized user can override it and continue.
  • Hard mandatory — a failure blocks the run with no override possible.

HCP Terraform also supports Open Policy Agent (OPA) policies as an alternative policy framework. Run tasks extend governance to third-party tools: at defined stages of a run (such as post-plan), HCP Terraform calls an external service — a security scanner, a compliance checker — and the task's pass/fail result can be advisory or mandatory for the run.

Finally, cost estimation: for supported AWS, Azure, and Google Cloud resources, HCP Terraform estimates the monthly cost of the plan and the delta against current cost, shown in the run output before apply. Sentinel policies can read the cost estimate, enabling rules like "fail any run that increases monthly spend by more than 20 percent."

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, the cloud block and terraform login flow, the three run-triggering workflows and execution modes, and Sentinel's three enforcement levels. Scenario questions describe a team problem — shared secrets, concurrent applies, PR review, cost control — and ask which HCP Terraform feature solves it.

Key takeaways
  • HCP Terraform (formerly Terraform Cloud) is HashiCorp's managed platform: remote runs, remote state with automatic locking, stored variables, and team governance; Terraform Enterprise is the self-hosted version.
  • Integration is two steps: terraform login stores an API token in credentials.tfrc.json, and a cloud block (organization + workspaces name or tags) connects the configuration — then terraform init, which can migrate existing local state.
  • The cloud block replaces the older remote backend and cannot coexist with a backend block; runs can be triggered CLI-driven, VCS-driven (merge to tracked branch, speculative plans on PRs), or API-driven.
  • An HCP Terraform workspace owns state, variables, run history, and permissions — a CLI workspace is only an alternate state file for one configuration. The standard pattern is one workspace per environment; projects group related workspaces for permissions and shared variable sets.
  • Workspace variables come as Terraform variables and environment variables; marking one sensitive makes it write-only. Variable sets share values across workspaces, projects, or the whole organization, with the most specific scope winning.
  • Execution modes: remote (default, runs on HCP Terraform), local (runs on your machine, state stays remote), and agent (self-hosted agents inside private networks).
  • Sentinel policy-as-code evaluates between plan and apply with three enforcement levels — advisory (warn), soft mandatory (overridable block), hard mandatory (no override); run tasks call external services during a run.
  • Cost estimation shows the projected monthly cost and delta for AWS, Azure, and GCP resources before apply, and Sentinel policies can enforce limits on it.

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 and is standard in Terraform 1.12, replacing the older backend "remote" configuration. A configuration cannot declare both a cloud block and a backend block at the same time.

Where does terraform login store its token, and what is it used for?

terraform login opens a browser so you can generate a user API token, then saves it in credentials.tfrc.json inside your ~/.terraform.d directory. The CLI uses that token to authenticate API calls to app.terraform.io — uploading configurations, streaming remote run output, and reading state. Team and organization API tokens also exist for automation.

What happens if a Sentinel policy fails during a run?

It depends on the enforcement level. Advisory logs a warning and the run continues. Soft mandatory blocks the run, but a user with override permission can force it to proceed. Hard mandatory blocks the run outright with no override. Policies are evaluated after the plan and before the apply.

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. Alternatively, local execution mode runs plans and applies on your own machine while still storing state in the workspace.

Test yourself on this topic
Practice questions with full explanations.
Practice now

Sign up free to mark lessons complete, bookmark topics and track your exam readiness.