- Codified rules: Security, compliance, and operational controls are written in a policy language so machines can evaluate them consistently.
- Version controlled: Policies live in VCS, are reviewed via pull requests, and follow the same change-management workflow as your infrastructure code.
- Automatically enforced: Policies run on each Terraform run. Checks are executed as part of the pipeline, removing manual gatekeeping and reducing human error.

- Author Terraform configuration (infrastructure as code).
- Push to HCP Terraform / trigger a run.
- Terraform performs a plan, then apply if the plan succeeds.
- Resources are provisioned in the cloud with no automatic compliance checks between plan and apply.

- Push configuration → run starts → plan phase
- Plan succeeds → policy check phase (evaluates the plan)
- Policies pass → apply phase → managed infrastructure
- Policies fail → run is blocked (depending on enforcement level)

- Restrict allowed regions or account IDs.
- Block public access to storage buckets.
- Disallow open security group rules or SSH from the Internet.
- Enforce instance sizing, tagging, or naming standards.
- Reject plans that exceed a monthly cost threshold (cost-aware policies).
Two policy frameworks in HCP Terraform
HCP Terraform supports two frameworks: HashiCorp Sentinel and Open Policy Agent (OPA). You can choose one or use both in the same environment.
Sentinel
- Built and maintained by HashiCorp.
- Deep integration with Terraform/HCP features and imports.
- Good starting point if you rely heavily on HashiCorp tooling and HashiCorp-provided policies.
- CNCF-graduated project with a large ecosystem.
- Rego is expressive for policies over structured data.
- Ideal when you want a cloud-native, multi-platform policy solution.
- The policy imports plan data via
tfplan/v2. - It defines unsupported source ranges representing the public Internet.
- It filters for managed
google_compute_firewallresources being created or updated and inspects their post-change attributes. - If any rule allows port 22 from
0.0.0.0/0or::/0, themainrule fails and blocks the run.
- This Rego policy iterates the plan’s resource changes.
- It looks for
aws_security_groupresources whose ingress rules include the CIDR0.0.0.0/0. - When found, it emits a deny message identifying the resource, causing the policy to fail.
Policies run only on successful plans. If a plan fails compilation or provider validation, policy checks are not executed because there is no plan data to evaluate.
- HashiCorp Sentinel: https://developer.hashicorp.com/sentinel
- Open Policy Agent (OPA): https://www.openpolicyagent.org/
- HCP Terraform policy enforcement (HCP docs) — search HCP Terraform policy enforcement in the HashiCorp docs for workspace-specific setup steps.