Sentinel for Terraform Introduction
What you'll learn: How HashiCorp Sentinel enforces policy-as-code directly within Terraform workflows to prevent infrastructure misconfigurations before they deploy.
What Is Sentinel?
Sentinel is HashiCorp's policy-as-code framework built specifically for Terraform Enterprise and Terraform Cloud. While you've learned about OPA (Open Policy Agent) for general policy enforcement, Sentinel is purpose-built to intercept and evaluate Terraform plans before infrastructure changes are applied. Think of it as a specialized gatekeeper that understands Terraform's native data structures and workflow stages.
How Sentinel Works in Terraform
Sentinel policies run between terraform plan and terraform apply. They examine the planned changes, existing state, and configuration to enforce rules like:
- Blocking expensive instance types
- Requiring specific tags on all resources
- Enforcing encryption settings
- Restricting geographic regions
Unlike generic policy engines, Sentinel has first-class awareness of Terraform concepts: resources, modules, providers, and the tfplan/tfstate data structures.
The Three Enforcement Levels
Sentinel policies operate at three severity levels:
- Advisory – warns but allows the change
- Soft-mandatory – blocks unless an authorized user overrides
- Hard-mandatory – blocks unconditionally, no exceptions
This graduated approach lets you balance governance with operational flexibility—stricter than static linting, but more nuanced than binary pass/fail gates.
Where It Fits
You've already used Terraform validation, Terratest for testing, and OPA for general policies. Sentinel sits between testing and deployment, acting as the final policy checkpoint in your CI/CD pipeline before actual infrastructure changes occur.
Key Takeaway: Sentinel provides Terraform-native policy enforcement with deep integration into Terraform's workflow, offering granular control over what infrastructure changes are permitted based on your organization's governance requirements.