skip to content

VCS-Driven Runs and Tasks

Connect a repository and pull requests get speculative plans while merges queue real runs; run tasks and policy sets sit at stages around them. Interviewers ask what can stop an apply and when.

part ofTerraformread it →
on this pageshow

questions

6

On an HCP Terraform workspace connected to GitHub, what does a pull request's speculative plan do, and why can it never apply?

level: middleimportance: must knowfreq 50%

answer

  1. review aid, not a queued change
  2. head branch against current state
  3. skips the queue and workspace locks
  4. the merge plans again from scratch

basics

~20 s

A speculative plan is a plan-only run HCP Terraform starts when a pull request opens or updates. It shows what the head branch would change against current state and cannot apply; the merge later queues a normal run that can.

solid answer

~40 s

When a pull request opens or updates against a workspace's linked branch, HCP Terraform starts a plan-only run using the head branch's contents against the workspace's current state, and links the result in the pull request. It cannot apply by design: plan-only runs ignore the run queue and workspace locks, never become the workspace's current run and do not block other runs, which is safe only because they change nothing. The real change comes from a new plan on the merged commit. Two limits matter in review: by default, pull requests from forks get no plan, and the result can go stale if the destination branch moves. The status check reports the plan only, so a green check says nothing about the later apply.

go deeper

for a junior

Remember the two-step shape: a pull request gets a plan that cannot apply, and the merge queues a normal run that can.

for a middle

Explain what the plan compares, head branch against current state, and why ignoring the queue and locks is safe only for a run that changes nothing.

for a senior

Point out what a green check hides: a skipped plan also passes, apply results never reach the status, and same-repository branches run code with workspace variables.

for a principal

Decide whether a passing speculative plan may stand in for human review, knowing it proves neither the merged result nor the apply.

## What a speculative plan is A **speculative plan** is a **plan-only run** in an HCP Terraform workspace. It runs Terraform's plan, shows the possible changes and the policies those changes affect, and stops. It exists to help people review a change before it merges. On a workspace connected to a repository, a speculative plan starts when a pull request is created or updated. HCP Terraform posts a link and a status indicator on the pull request and lists the plan among the workspace's other runs. If several workspaces connect to the same destination branch, one pull request carries links to several plans. ## When a pull request gets one HCP Terraform applies these rules each time a pull request is created or updated: - **Same repository only.** To avoid executing malicious code or exposing sensitive information, pull requests from forks get no speculative plan. Terraform Enterprise administrators can choose to allow them. - **Destination branch must match.** Only workspaces connected to the pull request's destination branch plan it. - **Setting must be on.** **Automatic speculative plans** is enabled by default and can be disabled per workspace. - **Paths must be relevant.** A workspace limited to certain directories skips pull requests that do not touch them, and still posts a passing commit status. A workspace that triggers only on published Git tags does not start these plans when a pull request opens or updates. ## Why it cannot apply The short answer is that the run type has no apply. The reasons behind that design are worth saying aloud: 1. **It skips the safeguards a real change needs.** Plan-only runs ignore the workspace's run queue and its locks, cannot become the current run, and do not block other runs. That freedom is acceptable only because nothing can change. 2. **Its input is not what will land.** It plans the head branch, while a normal run plans a commit on the linked branch. 3. **Its baseline moves.** It compares against the state at the time of the plan. Other runs may change that state before anyone merges. When the pull request merges, the new commit on the linked branch queues a **normal run**, with its own plan, policy evaluation and approval. The plan you reviewed is not carried forward. ## What runs on the way A speculative plan is not a bare `terraform plan`: - Policies are checked against it, so a pull request can reveal a policy failure before the merge. - Run tasks at the pre-plan and post-plan stages can fire, because all runs can enter those stages. The payload's `is_speculative` field tells the external service which kind of run it is seeing. - Pre-apply and post-apply tasks do not fire, since only confirmed runs reach pre-apply. - The plan runs the branch's code with the workspace's variables. That is why forks are excluded, and why write access to the repository deserves thought. ## What a green check does not prove | The pull request shows | It does not mean | |---|---| | A passing plan status | The later apply succeeded; HCP Terraform does not update the status with the apply's result | | A passing status on a monorepo pull request | The workspace planned it; a skipped plan also posts a pass | | A plan with few changes | The merged result will match, if the destination branch has moved | To get a more accurate picture after the destination branch has moved, rebase the head branch or merge the destination branch into it. Anyone on the repository can see the indicator, but only HCP Terraform organization members with permission to read runs can open the complete plan output. ## Other ways to start one Pull requests are one of three routes. With the CLI integration configured, `terraform plan` starts a speculative plan from local files. The UI's **Plan only** run type and the API start one as well. The UI route can select a different Terraform version without changing the workspace's settings, which makes it a cheap way to test an upgrade. An organization can also turn on **Automatically cancel speculative plans for outdated commits**, so new commits on a branch cancel the older unfinished plans.

  • Why does a fork's pull request get no speculative plan on HCP Terraform, and does a same-repository branch carry the same risk?
    Forks are excluded to avoid executing malicious code or exposing sensitive information. A same-repository branch does get a plan, which runs that branch's code with the workspace's variables, so write access to the repository effectively grants plan-time execution. Terraform Enterprise administrators can choose to allow fork plans, and that choice inherits the same risk.
  • A speculative plan passed on HCP Terraform and the merged commit's apply failed. How is that possible?
    A plan does not prove an apply will succeed, and the merged run is a different run: a different commit, possibly newer state. If the destination branch moved, the reviewed plan may not have shown the merged result. The pull request will not reveal the failure either, because its status is not updated with the apply's result.
  • Do HCP Terraform policies and run tasks fire on a speculative plan?
    Policies are checked against it, and pre-plan and post-plan run tasks can fire because all runs can enter those stages. Pre-apply tasks do not, because only confirmed runs reach that stage. An external service can read `is_speculative` in the payload to treat a pull request plan differently.
  • Many quick pushes to one pull request pile up speculative plans on HCP Terraform. What reduces the waste?
    The organization setting **Automatically cancel speculative plans for outdated commits** cancels ongoing or pending speculative plans when new commits arrive on the same branch. Canceled plans are identified in the run details and in the status checks, so reviewers can tell them from plans someone canceled by hand.

A speculative plan is a dress rehearsal: real script, real stage layout, full view of what would happen, and no audience. Opening night is a separate performance, and it can differ if the stage has changed since the rehearsal.

  • You can approve a pull request's speculative plan and apply that same plan after the merge.
  • A speculative plan waits its turn in the workspace's run queue like any other run.
  • A green HCP Terraform check on a commit proves its later apply succeeded.
  • A skipped speculative plan leaves the pull request's status pending until someone acts.
  • Speculative plans compare the pull request against the destination branch's code.
  • Everyone who can see the pull request can read the complete plan output.
open as a page

In an HCP Terraform run for a merged commit, which stages can stop the apply when a run task or a mandatory policy fails, and who can override?

level: seniorimportance: must knowfreq 46%

basics

~20 s

A mandatory run task can stop a run before the plan, after it or before the apply; a failed mandatory Sentinel or OPA policy stops it after the plan. Post-apply tasks stop nothing. Policy failures can pause for authorised override.

open as a page

In HCP Terraform, how do VCS-driven, CLI-driven and API-driven workflows differ in what starts a run and where its configuration comes from?

level: juniorimportance: should knowfreq 42%

basics

~20 s

VCS-driven runs start from webhooks and use a commit on the linked branch. CLI-driven runs start from terraform plan or apply and upload a local directory. API-driven runs start from your tooling, which uploads a tar.gz file.

open as a page

In HCP Terraform, how does a VCS trigger pattern differ from a run trigger between workspaces, and when would you use each?

level: middleimportance: should knowfreq 36%

basics

~20 s

A trigger pattern filters which changed repository files start a run in a VCS-connected workspace. A run trigger queues a run in one workspace after a source workspace applies successfully. One reacts to commits, the other to applies.

open as a page

In HCP Terraform, how do dynamic provider credentials replace stored AWS keys, and why might a run's plan authenticate while its apply fails?

level: seniorimportance: should knowfreq 38%

basics

~20 s

HCP Terraform sends a signed OIDC token for each plan and apply; AWS verifies it and returns temporary credentials. The token's sub claim names the run phase, so a trust policy matching only plan rejects the apply.

open as a page

As a platform lead on HCP Terraform, how do you decide which controls belong in a run task, which in a policy set and which outside the service?

level: principalimportance: should knowfreq 30%

basics

~20 s

Put rules decided from run data in policy sets, checks needing an outside system in run tasks, and anything that must hold even when no run happens outside the service, such as cloud role trust and repository protection.

open as a page