skip to content

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%

answer

  1. walk the run in order
  2. four task stages, one cannot block
  3. a timeout counts as a failure
  4. mandatory differs by framework
  5. override needs its own permission

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.

solid answer

~40 s

Walk the run in order. Run tasks sit at pre-plan, post-plan, pre-apply and post-apply, and a failed mandatory task, including a timeout, stops the run at the first three; post-apply tasks are advisory because the infrastructure already exists. Sentinel and OPA policies evaluate only after a successful plan and after post-plan tasks. What a failure does depends on the framework: a failed OPA `mandatory` or Sentinel `soft-mandatory` policy pauses in **Policy Override**, while a Sentinel `hard-mandatory` policy check ends in **Plan Errored** unless its set allows overrides. Overriding needs the manage policy overrides permission, which is separate from permission to apply runs. That second permission can discard the paused run, and it is also what the final confirmation needs, unless auto-apply is on.

go deeper

for a junior

Name the four run task stages in order, and recall that advisory warns while mandatory can stop the run.

for a middle

Place policy evaluation after a successful plan and after post-plan tasks, and explain why a timeout on a mandatory task counts as a failure.

for a senior

Trace a real failure to its state, Plan Errored or Policy Override, name the framework behind mandatory, and separate the override right from the apply right.

for a principal

Consider what each stopping point costs: a mandatory task ties deployments to an external service's availability, and every override right is a decision about who may accept risk.

## The run in order A **run** in an **HCP Terraform workspace** passes through stages, and several can end it. For a merged commit using Sentinel or OPA, the order is: 1. **Pending**, then **fetching** the configuration if needed. 2. **Pre-plan** run tasks, if any. 3. **Plan**. A failure here ends in **Plan Errored**. 4. **Post-plan** run tasks, if any. 5. **OPA policies** and Sentinel *policy evaluations*. 6. **Cost estimation**, if enabled. 7. Sentinel *policy checks*. 8. **Confirmation**, unless the plan can auto-apply. 9. **Pre-apply** run tasks, if any. Only confirmed runs get here. 10. **Apply**, then **post-apply** run tasks, if any. ## Run tasks: four stages, two levels A **run task** sends data about the run to an external service, which replies `passed` or `failed`. Each task is attached at a stage with an enforcement level. | Stage | The service receives | A failed mandatory task | |---|---|---| | Pre-plan | Configuration version, no plan yet | Run skips to **Plan Errored**, with no plan made | | Post-plan | Also the plan's JSON | Run skips to **Plan Errored** | | Pre-apply | Also the plan's JSON | Run skips to completion, after the run was confirmed | | Post-apply | Also the plan's JSON | Not applicable: this stage holds only advisory tasks | The rules that catch people out: - **Advisory** failures never stop a run; they leave a warning in the UI. - **Mandatory** includes timeouts and unexpected remote errors. After the initial `200 OK`, a service has 10 minutes to report a status or the task is assumed `failed`, and a request running over 60 minutes errors. - With several tasks, the most restrictive result wins: one failed mandatory task fails the run even if advisory tasks pass. - A post-apply failure cannot undo anything, because HCP Terraform has already provisioned the infrastructure. ## Policies: what mandatory means Policies evaluate only for successful plans. Enforcement levels belong to each policy, and the same word changes meaning between frameworks. | Framework and mode | Level | On failure | Can it be overridden? | |---|---|---|---| | Any | `advisory` | Warning, run continues | Nothing to override | | Sentinel policy check | `soft-mandatory` | Pauses in **Policy Override** | Yes | | Sentinel policy check | `hard-mandatory` | **Plan Errored** | No, unless the set allows overrides | | Sentinel policy evaluation | Either becomes `mandatory` | Stops the run | Yes | | OPA | `mandatory` | Pauses in **Policy Override** | Yes | The native Terraform policy framework, which requires Terraform 1.17 or later, has its own levels and timing, and its `mandatory` cannot be overridden, so name the framework whenever you say mandatory. ## Who can do what - **Override** needs the **manage policy overrides** permission. It is given by **Override and Continue** on the run page. For a Sentinel `soft-mandatory` failure, entering `override` at the `terraform apply` prompt also works. - **Discard** of a paused run needs permission to apply runs. So approving an apply and overriding a policy are separate rights. - **Confirm** at **Needs Confirmation** or **Policy Checked** also needs permission to apply runs, unless the plan can auto-apply. - An override covers that run only. It does not affect policy evaluations on future runs in the workspace. Run tasks differ here. The run-states page gives a failed mandatory task no **Policy Override** pause: the run ends in an errored state. The task-stages API does define an `awaiting_override` status and an override action, so check how your organization's setup behaves before promising anything. ## Walking the scenario Suppose a post-plan scanner task times out, and an OPA `mandatory` policy would also fail. 1. If the task is **mandatory**, the run ends in **Plan Errored** at post-plan, and the policy never evaluates. 2. If the task is **advisory**, a warning appears and the run reaches the OPA stage. 3. The policy fails and the run pauses in **Policy Override**. 4. A user with the override permission continues it to **Policy Checked**, or a user who can apply runs discards it. 5. The run then needs confirmation, unless it can auto-apply, and any pre-apply tasks run before the apply. The mistake to avoid is treating the first failure you see as the only gate. Each stage has its own consequence.

  • Can a failed mandatory run task in HCP Terraform be overridden the way a policy failure can?
    Do not assume so. The run-states page describes a mandatory task failure as ending the run in an errored state, with no **Policy Override** pause. The task-stages API does define an `awaiting_override` status, an override action and a separate `can-override-tasks` permission, so verify the behaviour in your own organization before relying on either answer.
  • Why would you attach an HCP Terraform run task at post-apply if it cannot block anything?
    Because some work only makes sense once infrastructure exists, and reporting it beats not knowing. A failure shows a warning on the run, which proceeds to **Applied**. Use a stage before the apply for anything that must prevent a change.
  • A policy needs cost estimate data in HCP Terraform. Does that constrain where it runs?
    Yes. Only Sentinel policy checks run after cost estimation and can read that data. Sentinel policy evaluations and OPA policies run immediately before cost estimation and cannot. Policy checks also support Sentinel only up to version 0.40.x, so HashiCorp recommends evaluations otherwise; a cost rule is the case that keeps you on checks.
  • Why can you not override a policy failure on an HCP Terraform plan with no infrastructure changes?
    HCP Terraform does not allow overrides for no-operation plans unless the run was started with the **Allow empty apply** option. Without changes there is normally no apply to reach, so there is nothing for an override to unlock.

  • A mandatory post-apply run task can stop or roll back a bad apply.
  • If a mandatory run task's service never answers, the run continues because no verdict arrived.
  • An advisory run task that fails holds the run until someone acknowledges it.
  • Mandatory means the same thing for run tasks, Sentinel and OPA.
  • Anyone who can approve an apply can also override a failed policy.
  • Overriding a policy failure waives that policy for later runs in the workspace.

Assumes Terraform 1.17: HCP Terraform's native Terraform policy framework requires 1.17 or later; the Sentinel and OPA behaviour described is HCP Terraform's own.