skip to content

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%

answer

  1. what does the control need to know
  2. what happens when the checker is down
  3. what if no run ever happens
  4. who may bypass, and who owns it

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.

solid answer

~50 s

I sort each control by three questions, and there is no universal split. What does it need to know? If the plan and run data are enough, a policy set is the natural home, with framework levels, scoping by project or tag, and a built-in override path. If it needs an outside system, it is a run task, chosen for the stage where its data exists. What happens when the checker fails? A mandatory run task fails closed on a timeout, so that service's availability becomes your deployment's availability. What if no run happens at all? Local execution sidesteps both, and a workspace excluded from a policy set escapes that set, so anything that must always hold goes outside the service: cloud role trust scoped to the workspace and phase, repository rules, and cloud-side guardrails.

go deeper

for a junior

Know the basic difference: a policy set is evaluated inside HCP Terraform, and a run task calls an external service.

for a middle

Explain which stage gives a run task the plan JSON, and how a policy failure can pause for an override while a mandatory task timeout fails the run.

for a senior

List real bypasses: Local execution mode, policy set exclusions, a task dissociated from a workspace, an old Terraform version, and direct cloud credentials.

for a principal

Own the map, not one mechanism: for each control state its layer, what happens if its checker fails, who may override it and which team answers when it blocks a release.

## The decision HCP Terraform offers two ways to gate a run from inside, and a lead must also decide what should not depend on a run existing. There is no single right split. It depends on your risk, your vendors and who owns what. The useful habit is to ask the same questions of every control. | | Policy set | Run task | Outside the service | |---|---|---|---| | Decides from | Plan and run data | Whatever the external service knows | The target system's own rules | | Runs at | After a successful plan, for Sentinel and OPA | Pre-plan, post-plan, pre-apply or post-apply | Every request, whatever issued it | | When its checker fails | Handled inside the service | Mandatory fails the run, including timeouts | Depends on that system | | Override | Built in, with a permission | The run-states page shows no override pause | Your own process | | Reach | Global, project, workspace or tag | Workspace, or wider with an entitlement | Whatever you scope it to | ## When a policy set fits Choose a **policy set** when the rule can be decided from what the run already holds: - Rules about planned resources, regions, tagging or which changes need a person. - Rules that need an override path with a named permission, since a run can pause in **Policy Override**. - Rules with broad reach. A set can apply globally, to projects and workspaces, or to workspaces with matching tags. - Rules that should read cost estimates. Only Sentinel policy checks can, and checks support Sentinel only up to 0.40.x, so that choice has a cost. How the rule itself is written, and how enforcement rolls out, are separate decisions. ## When a run task fits Choose a **run task** when the decision needs something HCP Terraform does not have, such as an external registry, a third-party tool or an internal approval record. Then choose the stage by the data it needs: 1. **Pre-plan** gets the configuration version, with no plan yet. 2. **Post-plan** is the earliest stage with `plan_json_api_url`, and the usual place for a plan-based check. 3. **Pre-apply** fires only for confirmed runs, which suits a check that should happen just before the change. 4. **Post-apply** can only report, since the infrastructure already exists. The costs to accept openly: - **Availability.** A service must report progress within 10 minutes, and a mandatory task that times out fails the run. An outage there stops every workspace using that task. - **Data leaving.** The service receives an `access_token` and URLs to fetch the configuration and plan. You are trusting it with infrastructure detail, and an HMAC key only proves the request came from HCP Terraform. - **Silent gaps.** A workspace moved to a Terraform version before 1.1.9 no longer triggers run tasks, without an error. - **Local removal.** Users with **Manage workspace Run Tasks** can dissociate a task from a workspace. Enforcing it at organization or project scope depends on the plan. ## What belongs outside Both mechanisms gate a run. They have nothing to say about a change that never became one: - In **Local** execution mode, Terraform runs on your own machines and the workspace only stores state. Sentinel policy enforcement is among the features documented as unavailable there. - A global policy set can exclude projects, workspaces or tags by design, and a workspace admin can change workspace settings. - Anyone holding cloud credentials can change resources with no run at all. So controls that must always hold sit where the change lands. Dynamic provider credentials help: if a role's only trust statement matches one workspace and `run_phase:apply`, that workspace's apply is the only way to obtain it through this trust. Repository rules protect what reaches a VCS-linked branch. Cloud-side guardrails and drift review handle the rest, and those are their own subjects. ## Questions to ask of every control 1. Can it be decided from the run's own data? 2. If its checker is down, should deployments stop? 3. Must it hold when no run happens? 4. Who may override it, and is that recorded? 5. Which team is on call when it blocks a release? Layering is normal. The same concern may appear as a pull request plan's early warning, a mandatory gate and a cloud-side limit. What a lead should avoid is one control that everybody assumes someone else's layer enforces.

  • Your mandatory run task's vendor has an outage and every HCP Terraform apply is failing. What should have been decided beforehand?
    Who may change the task's enforcement level or remove it from a workspace, how that change is recorded, and what compensating check applies meanwhile. Timeouts fail mandatory tasks by design, so this is a decision to make in advance. If an outage may not stop deployments, advisory plus a separate control may be the honest choice.
  • When is a pre-apply HCP Terraform run task better than a post-plan one?
    When the check should sit as close to the change as possible, or should apply only to runs someone has confirmed. Only confirmed runs enter pre-apply, so speculative plans never reach it. The trade-off is that a failure arrives after a person has already approved, while post-plan reports early and can also inform pull request reviewers.
  • A team moves an HCP Terraform workspace to Local execution mode to speed up its work. Which of your controls still apply?
    Do not count on run-based ones. Terraform now runs on their machines, the workspace only stores state, and Sentinel enforcement is documented as unavailable with local operations. Cloud role trust matching HCP Terraform's tokens still applies, because their local runs cannot use that path. Decide who may change execution mode as part of your control design.

  • Policy sets and run tasks together cover every way infrastructure can change.
  • A mandatory run task costs nothing extra compared with a policy, because both just block.
  • A post-apply run task is a suitable place for a control that must prevent a change.
  • Every control should live in one layer, so that ownership stays simple.
  • An HMAC key on a run task limits what data the external service can read.
  • A policy set applied globally cannot have any workspace excluded from it.