Define policies overview
This topic provides overview information about how to define policies as code. Policies are rules for enforcing how Terraform provisions infrastructure as code for your workspaces and projects.
Workflows
You can use three policy-as-code frameworks to define fine-grained, logic-based policies: Terraform policy, Sentinel, or Open Policy Agent (OPA). Depending on the settings, policies can act as advisory warnings or firm requirements that prevent Terraform from provisioning infrastructure.
- Terraform policy (beta): Define policies in HCL. Because Terraform configuration language also uses HCL syntax, it should be familiar to infrastructure-as-code developers. The common syntax also allows you to natively integrate with Terraform workflows. Refer to Define Terraform policy for details.
- Sentinel: You define policies with the Sentinel policy language and use imports to parse the Terraform plan, state, and configuration. Refer to Define custom Sentinel policies for details.
- OPA: You define policies with the Rego policy language. Refer to Defining OPA Policies for details. The following table compares select characteristics of the supported policy frameworks. For a more detailed comparison, refer to Compare policy frameworks.
| Characteristic | Terraform policy | Sentinel | OPA |
|---|---|---|---|
| Language | HCL | Sentinel | Rego |
| Language complexity | Low for Terraform users | Medium | High |
| Native Terraform integration | Yes | No | No |
| Testing framework | Built-in | Built-in | External |