Lesson 4 of 4 HCP Terraform Organization and Governance

Policy Enforcement, Health Assessments and Explorer

HCP Terraform's governance features check runs against rules, watch infrastructure after deployment and report across the organisation. This lesson covers policies, run tasks, health assessments, explorer and change requests.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe policy sets and Sentinel and OPA enforcement levels.
  • Explain drift detection and continuous validation.
  • Describe the purpose of explorer and change requests.

Policy enforcement

Policy as code expresses rules that every run must follow, such as "all buckets must be encrypted" or "only approved instance types". HCP Terraform supports two policy languages: Sentinel, HashiCorp's own language, and Open Policy Agent (OPA), which uses the Rego language. Policies are grouped into policy sets, usually stored in a VCS repository, and applied to the whole organisation, to projects or to selected workspaces.

Policies are evaluated after the plan and before the apply, against the plan, the configuration and the state. The enforcement level decides what happens when a policy fails.

Enforcement levelLanguageOn failure
AdvisorySentinel and OPAWarning; the run continues
Soft-mandatorySentinelThe run stops unless a user with permission overrides it
Hard-mandatorySentinelThe run stops; no override is possible
MandatoryOPAThe run stops unless a user with permission overrides it

Policy enforcement is available in the Standard and Premium editions; check the current plans.

The following diagram compares the three Sentinel enforcement levels.

Choosing the enforcement level for a no-exceptions encryption rule. Advisory only warns, soft-mandatory can be overridden by authorised users, and hard-mandatory blocks every non-compliant run with no override, so it fits. An explorer query on module versions finds the workspaces still using the old storage module.
OPA policies use mandatory and advisory levels.
Match the pairs

Enforcement levels

Exam skills 8.2.2

Match each policy enforcement term with what it means.

Log in to try this activity Interactive activities are free with an account.

Run tasks

Run tasks connect runs to external services, such as security scanners, cost management tools or ticketing systems. At a chosen stage, pre-plan, post-plan, pre-apply or post-apply, HCP Terraform sends run details to the service and waits for its result. A task configured as mandatory stops the run if the service reports a failure; an advisory task only shows the result.

Sort into groups

Which governance feature?

Exam skills 8.2.2 · 8.2.3

Choose the HCP Terraform feature that meets each requirement.

Log in to try this activity Interactive activities are free with an account.

Health assessments

After apply, infrastructure can still drift or degrade. Health assessments run automatically on a schedule in eligible workspaces and include two evaluations. Drift detection runs a refresh-only plan to find differences between real infrastructure and state. Continuous validation re-evaluates the configuration's custom conditions, including check blocks, so a certificate that is about to expire or a health endpoint that fails is reported without a new run. Results appear on the workspace's Health page and can trigger notifications.

Assessments require remote or agent execution mode and a successful apply, are paused while the latest run is in an errored state, and never interfere with runs. Organisation owners can enforce them across all workspaces. Health assessments are available in the Standard and Premium editions.

Select all that apply

Health assessments

Exam skills 8.2.3

Identify the facts about HCP Terraform health assessments.

Log in to try this activity Interactive activities are free with an account.

Explorer and change requests

The explorer gives a queryable view of the whole organisation. Built-in queries list workspaces with drift or failed checks, the most used module and provider versions, the Terraform versions in use, workspaces by VCS repository and runs by status, and the query builder filters any field. It answers questions such as "which workspaces still use module version 1.x?".

From explorer results, administrators can create change requests: action items recorded on the selected workspaces, such as upgrading a deprecated module, applying a security fix or correcting a compliance problem. Team notifications can alert workspace owners, and owners archive a request when it is done. Change requests are available in the Standard and Premium editions.

Policy enforcement
When it actsDuring each run, before apply
What it checksPlans against Sentinel or OPA rules
ResultPass, warn or block the run
Health assessments
When it actsOn a schedule after apply
What it checksDrift and custom conditions
ResultHealth status and notifications
Explorer and change requests
When it actsOn demand
What it checksData across all workspaces
ResultReports and action items
Worked example

Enforcing encryption

A compliance team requires that no unencrypted storage is ever created, with no exceptions, and wants to know which existing workspaces still use an old storage module that predates the rule.

The decisive requirements are a block that cannot be overridden, and an organisation-wide inventory.

A Sentinel policy that checks every planned storage resource for encryption, in a policy set applied to the organisation with the hard-mandatory enforcement level, blocks any non-compliant run without override. A soft-mandatory level would let authorised users override it, which the rule forbids. An explorer query on module versions finds the workspaces using the old module, and change requests record the upgrade on each of them.

Check yourself

Which Sentinel enforcement level blocks a run with no possibility of override?

Show answer

Hard-mandatory.

Exam Tips

Remember for the exam

  • Sentinel levels: advisory, soft-mandatory (overridable), hard-mandatory (not overridable).
  • Policies run after plan and before apply.
  • Health assessments: drift detection plus continuous validation, on a schedule.
  • Explorer queries the organisation; change requests record work on workspaces.