Module 8: HCP Terraform
Lab 8B: VCS-Driven Workflow, Speculative Plans, and Governance Walkthrough
- Time
- 30 min
- Cost
- $0
- Prerequisites
- None listed
Setup
Create a new GitHub repo, tf-course-vcs. Copy lab8a/main.tf into it, remove the cloud block (VCS-driven workspaces don't need one), and add this check block for later:
check "pet_has_two_words" {
assert {
condition = length(split("-", random_pet.app.id)) >= 2
error_message = "Pet name is unexpectedly short."
}
}Commit and push to main.
Steps
- In the
tf-courseproject, choose New → Workspace → Version Control Workflow → GitHub. Authorize the HCP Terraform GitHub App if prompted. - Select
tf-course-vcsand name the workspacetf-course-vcs-dev.
Expected output: HCP Terraform queues a plan automatically from main. It uses pet_length = 2, because this workspace has no workspace variable, but it inherits owner from the project variable set.
Open the run. Notice that auto-apply is off by default, so the run waits. Select Confirm & Apply and add a comment. Expected output: the run reaches Applied. The check result appears in the run, and it passes.
git checkout -b longer-pet
sed -i.bak 's/default = 2/default = 3/' main.tf && rm main.tf.bak
git commit -am "Longer pet names" && git push -u origin longer-petOpen a pull request on GitHub. Expected output: an HCP Terraform status check appears on the PR, linking to a speculative plan that shows the replacement. Speculative plans can't be applied.
Merge the pull request.
Expected output: a new run starts on main. Confirm and apply it in the UI.
Locally, in a clone of the repo, add a cloud block pointing at tf-course-vcs-dev, then run:
terraform init && terraform applyExpected output: an error saying apply isn't allowed for workspaces with a VCS connection. terraform plan from the CLI still works and produces a speculative plan. Remove the cloud block and don't commit it.
In Actions → Lock workspace, lock it, then push a trivial commit, such as a README change. Expected output: the run queues but can't proceed until you unlock the workspace. Unlock it, and the run continues.
These features may not be included in a free plan. Click through whichever are available to you. If a page shows an upgrade prompt, read its description instead.
| Where | What to look at |
|---|---|
| Organization Settings → Teams | Create a team and grant it Plan access on the tf-course project. Note the fixed levels: Read, Plan, Write, Admin. |
| Registry → Publish → Module | Note how a VCS repo named terraform-<provider>-<name> with semantic version tags becomes a private module. Lab 5's repo would need renaming to qualify. |
| Organization Settings → Policy sets | Note the choice between Sentinel and OPA, scoping to the organization, projects, or workspaces, and the enforcement level options. |
| Organization Settings → Run tasks | Note the stage choices (pre-plan, post-plan, pre-apply, post-apply) and the advisory vs. mandatory setting. |
| Workspace → Settings → Health | If available, enable health assessments, which cover drift detection and continuous validation of the check block you committed. |
Cleanup
- In
tf-course-vcs-dev, go to Settings → Destruction and Deletion, queue a destroy plan, and confirm it. - Delete the workspace, the
tf-course-sharedvariable set, and thetf-courseproject. - Delete or archive the GitHub repo if you no longer need it.
- Optionally run
terraform logout.
This lab has no verification checklist in the course file, so it counts as complete when every step is checked.