Pro ยท Lesson 10 of 12

CI and HCP Terraform

A pipeline should run the same commands a careful person runs: format, validate, test, plan, and a reviewed apply. HCP Terraform is one place those remote runs can live. It is a HashiCorp product.

Sign in to save your place.

Picture it this way

CI is a clerk who refuses to file a plan they did not print. HCP Terraform is HashiCorp's office for that clerk. You can hire a different clerk. Do not assume the other clerk has the same keys.

A small pipeline

Pin the Terraform version in the runner image or the version manager the runner actually uses. Run terraform fmt -check, terraform init -input=false, terraform validate, and terraform test on pull requests. Run terraform plan with saved output when the change should be reviewed. Apply from a protected branch or a reviewed run, not from a laptop that happens to have production credentials.

Store the plan and the state where the team can see them. A plan file is stale if someone else applies first. That is what the lock is for.

What HCP Terraform adds, and what it does not

HCP Terraform, the product formerly called Terraform Cloud, runs remote plans and applies, stores remote state, and can require a human to confirm a run. Workspaces there are the remote environments from the workspaces lesson. Policy sets can use Sentinel, which is HashiCorp's policy product. Open Policy Agent shows up in some HashiCorp policy stories as well. Read the current policy page before you name a policy engine in a design.

HCP Terraform does not apply an OpenTofu configuration by you selecting OpenTofu in your heart. The runner is theirs. If you need tofu, use a CI job that installs OpenTofu and calls it, or a product that documents OpenTofu support. Do not write "HCP Terraform or any OpenTofu equivalent" as if a specific equivalent shipped with the same features.

Step Pull request Protected apply
fmt -check Yes Yes
validate and test Yes Yes
plan Yes, as a comment or artifact Yes, and a human reads it
apply No Yes, after the plan is approved

A change becomes a run

  1. Pull request
  2. Plan
  3. Apply

Step 1 of 3The pull request runs fmt, validate, and tests.

Lab: write the pipeline as comments you could paste into CI

Do not point this at a production backend. The commands are the contract.

terraform version
terraform fmt -check -recursive
terraform init -input=false
terraform validate
terraform test
terraform plan -input=false -out=tfplan
# apply only on the protected path:
# terraform apply -input=false tfplan

Concept summary

Knowledge check

Where should apply run?

What is Sentinel in this lesson?

A team standardizes on OpenTofu. What do they need in CI?

Official sources

Checked against the linked documentation in October 2026. A later release can move a flag, a price, or a supported pair. Use the page for the version you installed.