deploymentRequest.revision: the revision the deployment uses. When the deployment doesn’t set one, env zero uses the environment’s last deployed revision, then the template’s revision.template.revision: the revision set on the template.
Prerequisites
- The Edit Organization Settings permission
- A repository for the policy that deployers can’t change, separate from the code they deploy, so changes to the approved revisions go through your git review
- An API key ID and secret
The policy
Every environment must deploy its template’s revision, unlessapproved_revisions lists the environment with its own revision. Find an environment’s ID in the details card at the top of the environment page.
pin-revision.rego
- A deployment is denied when its revision doesn’t match, or when the environment isn’t in
approved_revisionsand its template has no revision. - Applies from pull request comments are denied in every environment. They run the pull request’s branch, while
deploymentRequest.revisionstill shows the environment’s revision. - Destroys and pull request plans aren’t checked against the approved revision.
approved_revisions, and then redeploy each affected environment with the new revision. Until you do, deployments that don’t set a revision, including scheduled deployments, use the environment’s last revision and are denied.
Keep approved_revisions in the policy file. Don’t load it through ENV0_POLICY_DATA_PATH: that file is read from the repository being deployed, which deployers control.
Allow a team to bypass the check
The policy input doesn’t include user roles, so an exception for administrators has to be based on the deployer’s teams. Add this rule, and addnot exempt as the first line of the checked rule. Deployments by members of the team skip every check in the policy.
Assign the policy to the organization
The organization Policies page lists only policies from the env zero policy catalog, and the Terraform provider assigns approval policies only to projects (PROJECT) and templates (BLUEPRINT). Assign a custom policy to the organization with the API.
1
Create the approval policy
Point it at the repository and folder that hold your
.rego file. Use the env0_approval_policy Terraform resource and read its id, or add the policy to a template as described in Template approval policies.To find the ID of a policy you added to a template, list the policies assigned to it:2
Assign it to the organization
Find your Organization ID under Organization Settings, then run:
3
Test it
Deploy an environment on a revision that isn’t approved. The deployment is cancelled, and the Approval Policies step of the deployment log shows
Policy result: deny with the policy’s message.Next steps
- Manage approval policies - Full policy input reference and result types.
- Plan and apply from PR comments - The PR comment applies this policy denies.
- Role-based access control (RBAC) - Control who has Edit Organization Settings.