Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
HashiCorp · Terraform 004

HCP Terraform runs and CLI integration

Terraform 004 · Lesson 17 of 18 · 2:05:45

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the HashiCorp Terraform Associate (004) exam. In this lesson: the editions of Terraform (Community, HCP Terraform, Terraform Enterprise), HCP Terraform workspaces and their execution modes, VCS, CLI, and API workflows, speculative plans, and the cloud block. Includes three original practice questions, with Bluefin Logistics, a fictional parcel delivery company, as the example.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

Runs on laptops

Bluefin's Terraform runs still happen on laptops, and the state sits in a bucket that only the platform team can reach. The team wants shared runs, one place for variables and secrets, and a history of every change. This lesson covers HCP Terraform: its editions, its workspaces, its workflows, and how the CLI connects to it.

Three editions

Terraform comes in three editions. Community Edition is the free CLI that you have used so far, and it runs wherever you install it. HCP Terraform is the managed service of HashiCorp: it runs Terraform remotely, stores the state and the secrets, and adds a web interface, access control, a private registry, and an API. Terraform Enterprise is the self-hosted distribution of HCP Terraform, for organizations with strict security and compliance requirements, and it supports air-gapped installations. In HCP Terraform, an organization holds projects, and each project holds workspaces.

Workspaces

An HCP Terraform workspace is where one configuration is managed: it holds the configuration, its variables, every version of its state, and the history of its runs. It is not the same thing as a CLI workspace, which only keeps a separate state in the same backend. Each workspace has an execution mode. In remote mode, HCP Terraform runs Terraform on its own disposable machines; in local mode, runs happen on your machine and HCP Terraform only stores the state; and in agent mode, agents run Terraform inside a private network.

Workflows and runs

HCP Terraform has three workflows for runs. In the VCS-driven workflow, a workspace is linked to a repository: a commit to its branch starts a run, and a pull request gets a speculative plan, a plan-only run that cannot apply any changes. In the CLI-driven workflow, terraform plan and terraform apply run remotely in HCP Terraform, and the output streams back to your terminal. The API-driven workflow lets your own tooling start runs. A run moves through stages, from the plan to policy checks and cost estimation, and by default it waits for someone to confirm the apply, unless the workspace has auto-apply turned on.

The cloud block

To connect the CLI, run terraform login first: it gets an API token and saves it in plain text, in a file named credentials dot T F R C dot json. Then add a cloud block inside the terraform block, available since Terraform 1.1, with your organization, an optional hostname, which defaults to app dot terraform dot I O, and a workspaces block. The workspaces block names one workspace, or selects workspaces by tags, but not both, and it can also name a project. Run terraform init: when a local state already exists, init offers to migrate it to HCP Terraform. A configuration cannot have both a cloud block and a backend block, and a remote apply from the CLI is refused on a workspace that is linked to a repository.

Recap

Let's recap. Community Edition is the free CLI, HCP Terraform is the managed service, and Terraform Enterprise is its self-hosted version, air-gapped if needed. An HCP Terraform workspace holds a configuration, its variables, its state versions, and its runs, with a remote, local, or agent execution mode. Runs come from a repository, with speculative plans for pull requests, from the CLI, or from the API, and they wait for a confirmation unless auto-apply is on. And terraform login, a cloud block, and terraform init connect the CLI, and migrate a local state.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. Bluefin's parent company is a bank whose servers have no internet access, and it wants the features of HCP Terraform inside its own network. Which edition fits?

    • Community Edition, run on the bank's servers
    • HCP Terraform, with a private registry
    • Terraform Enterprise, self-hosted
    • HCP Terraform, with agents in the bank
    Show the answer

    Terraform Enterprise, self-hosted

    Terraform Enterprise is the self-hosted distribution of HCP Terraform, and it supports air-gapped installations. “Community Edition, run on the bank's servers” is wrong, because Community Edition is only the CLI, without the shared features. “HCP Terraform, with a private registry” is wrong, because HCP Terraform is a managed service, which the servers of the bank cannot reach. And “HCP Terraform, with agents in the bank” is wrong, because agents still need an outbound connection to HCP Terraform.

  2. Bluefin's tracking workspace is linked to a GitHub repository, and an engineer opens a pull request against its main branch. What happens in HCP Terraform?

    • It applies the changes to production at once
    • Nothing runs until the pull request is merged
    • It creates a new workspace for the branch
    • It runs a speculative plan, for review only
    Show the answer

    It runs a speculative plan, for review only

    A pull request gets a speculative plan, which shows the changes for review but cannot apply them. “It applies the changes to production at once” is wrong, because only a commit to the linked branch, after the merge, starts a run that can apply. “Nothing runs until the pull request is merged” is wrong, because the speculative plan runs as soon as the pull request is opened. And “It creates a new workspace for the branch” is wrong, because the plan runs in the workspace that is linked to the repository, with no new workspace.

  3. Bluefin's parcel API still keeps its state in a local file, and the team wants to move it to an HCP Terraform workspace. Which steps work?

    • terraform login, a cloud block, then terraform init
    • terraform apply with the -migrate-state option
    • Paste the state into a workspace variable
    • A cloud block and a backend block together
    Show the answer

    terraform login, a cloud block, then terraform init

    Login saves the token, the cloud block names the organization and the workspace, and init offers to migrate the local state. “terraform apply with the -migrate-state option” is wrong, because migrate state is an option of init, not of apply. “Paste the state into a workspace variable” is wrong, because workspace variables hold input values, not the state. And “A cloud block and a backend block together” is wrong, because a configuration cannot have a cloud block and a backend block together.