Writing Sentinel policies to enforce rules on Terraform templates
In this section, we will learn about HashiCorp Sentinel and how we can enable it in Terraform Cloud. After that, we will write a Sentinel policy to enforce rules on Terraform templates.
HashiCorp Sentinel
Sentinel is a framework for policy and language, built in software to enforce fine-grained, logic-based policy decisions. It is an enterprise feature of Terraform, Vault, Nomad, and Consul. Sentinel is easy to learn and needs minimal programming experience. Sentinel policies are written in a text file using the Sentinel language with the .sentinel
file extension. The Sentinel language has a main
function, whose value decides whether a policy passes or fails. Here's an example:
main = 9 > 3
When you execute this policy using a Sentinel command, the result will be true
. Sentinel handles the result of the execution in levels known as an enforcement level. Sentinel has three enforcement levels:
-
...