Use HashiCorp managed pre-written policies
Policy sets are collections of policies you can apply globally, to specific projects and workspaces, to workspaces with specific tags in your organization, or to Terraform Stacks. For each run in the applicable workspaces or Stack, HCP Terraform checks the Terraform plan against the policy set. Depending on the enforcement level, failed policies can stop a Terraform run. If you do not want to enforce a policy set on a specific project, workspace, tag, or Stack you can exclude it from that set.
View existing pre-written policies
- Sign in to HCP Terraform and navigate to your organization.
- Click Settings, then Pre-written policies in the sidebar.
This page contains all of the pre-written policies available in the organization, organized by framework.
Filter pre-written policies
From the pre-written policies page you can filter the available policies using the top filter bar.
- Click the Filters dropdown in the top bar of the table.
- Select the filters to apply among Provider, Services, Compliance framework, and Governed resources, and then click Apply.
View pre-written policy details
From the pre-written policies page you can click on any policy to view the details of a policy.
- Click on a policy name in the table.
- Review the main details of the policy from the Overview section.
- Review the policy code from the Policy code section.
- Review the policy sets where the policy is used in the Connected policy sets section.
Clicking on a policy set name in the Connected policy sets opens the details page for that policy set.
Create new policy set using pre-written policies
Sign in to HCP Terraform and navigate to your organization.
Choose Settings from the sidebar, then Policy sets.
Choose the Pre-written policies option.
Select one of the following frameworks:
- Terraform policy: Terraform policy is a policy-as-code framework that integrates directly with Terraform providers. It supports policies written in HashiCorp Configuration Language (HCL) syntax, which lets you reference any resource defined in a Terraform provider.
- Sentinel: Sentinel is a language and framework for policy built to be embedded in existing software to enable fine-grained, logic-based policy decisions. Sentinel policies are written using the Sentinel language.
A policy set can only contain policies that use the same framework. You cannot change a policy set's framework type after creation.
From the table, select all policies you want to add to the policy set.
- Click on a policy name to view the policy details.
- Use the filter bar to search for specific policies.
- Select all desired policies.
Click on the Next button.
Use the ... button for each policy or the Actions dropdown to define the enforcement level for the selected policies. Refer to Policy enforcement levels for more information.
Click on the Next button.
Configure the policy set by adding:
- Policy set name: a unique name for the policy set. You can use any combination of letters, numbers,
-, and_. A name is required. - Policy set description: an optional description of the policy set behavior.
- Scope of policies: the scope the HCP Terraform applies the policies to. Refer to Policy set scope for details.
- Policy set name: a unique name for the policy set. You can use any combination of letters, numbers,
Click Create policy set to finish.