Plan Policies
A policy is a rule checked against what a plan will change. It runs after the plan, on the plan JSON, and either reports a violation or fails the run before apply.
The pre-plan checks (validate, tflint, checkov) read your code before the plan. Policies read the plan, so they see default_tags, values computed inside modules, and anything else only the plan knows.
Manage policies
Open Organization → Settings → Policies. Every member can view policies; creating, changing or deleting one needs the write_organizations permission, which org admins have.
The API is GET/POST /api/organizations/{org}/policies/ and GET/PATCH/DELETE /api/organizations/{org}/policies/{id}/. A policy has these fields:
name,descriptionkind: one of the four kinds belowconfig: the kind's settingsenforcement:off,advisoryorblockingworkspace_tags: the policy applies to workspaces whose tags contain all these pairs. Empty means every workspace.
{
"name": "Production must be tagged",
"kind": "require_tags",
"config": { "tags": ["owner", "cost-center"] },
"enforcement": "advisory",
"workspace_tags": { "env": "prod" }
}
Or manage them as code with infradots_policy in the Terraform provider.
Kinds
require_tags
Every resource that has a tags argument must carry these keys. Provider default_tags count, because the check reads tags_all. Resources with no tags argument, such as aws_s3_bucket_acl, are skipped.
{ "tags": ["owner", "cost-center"] }
attribute
Checks one attribute. resource_type is a type such as aws_s3_bucket_acl, or * for every resource that has the attribute. path is dotted: acl, tags.owner, region (version 6.x of the AWS provider sets region on every resource).
op is one of:
eq:valueis a string, number or boolean. The dashboard sends the value as text.in/not_in:valueis a list of strings.exists: novalue.
{ "resource_type": "aws_s3_bucket_acl", "path": "acl", "op": "eq", "value": "private" }
{ "resource_type": "*", "path": "region", "op": "in", "value": ["eu-central-1", "eu-west-1"] }
Lists inside attributes, such as ingress.*, are not supported yet.
no_open_ingress
Flags an aws_security_group whose inline ingress block is open to 0.0.0.0/0 on any of the ports. Separate aws_vpc_security_group_ingress_rule resources are not checked.
{ "ports": [22, 3389] }
no_delete
Flags any resource the plan deletes or replaces. It takes no settings.
{}
Resources the plan deletes are not checked against the tag, attribute or ingress kinds.
What happens on a run
After the plan, the run shows a Policy checks stage listing each violation with its enforcement, the resource address and a message. Read it from the CLI with idp job output <job-id> --stage policy.
- Advisory violations are reported and the run continues.
- Blocking violations fail the run before apply. That holds with auto-apply and with manual approval: the run never reaches Waiting Approval.
Only runs that can apply are stopped: plan-and-apply and destroy. Plan-only runs, such as pull request plans and drift checks, show the stage but keep their own status.
The plan JSON is masked, so sensitive values are not visible to a policy. Don't write rules on sensitive attributes.
When the check cannot run
Blocking policies fail closed. If a blocking policy applies and the check cannot run (the policy service is unreachable or times out, or the plan JSON was not uploaded), the run fails and says why. If only advisory policies apply, the run continues with a notice.
Requirements and limits
- A run with a blocking policy needs executor 1.23.0 or later. On a self-hosted runner with an older executor, the run fails with "Upgrade it to 1.23.0 or later".
- Policies cannot check Terragrunt plans yet. A blocking policy that applies to a Terragrunt workspace fails its apply runs. Make it advisory, or scope it away with
workspace_tags.
Start with advisory, watch the stage on a few runs, then switch to blocking.
