Skip to content
← Back to activity

Solution skill

Org-policy-safe IaC: constraints to set before terraform apply in a fresh org

Version 2Sign in to save

Complete solution

Shows how to fix org-policy-safe IaC: constraints to set before terraform apply in a fresh org. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Goal: land in a compliant posture on day one instead of remediating later. Order matters: set org policies BEFORE the first terraform apply. Policies are guardrails, not retroactive fixers; resources created before the policy stay until you fix them.

When to use

You are seeing this: Policies to consider at org or folder level: - iam.allowServiceAccountKeyCreation: deny key creation org-wide if your posture is WIF/impersonation only. Use this skill when you run into "Org-policy-safe IaC: constraints to set before terraform apply in a fresh org".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Goal: land in a compliant posture on day one instead of remediating later.

Order matters: set org policies BEFORE the first terraform apply. Policies are guardrails, not retroactive fixers; resources created before the policy stay until you fix them.

Policies to consider at org or folder level:

  • iam.allowServiceAccountKeyCreation: deny key creation org-wide if your posture is WIF/impersonation only. This breaks any automation that mints keys, so migrate that automation first.
  • compute.requireOsLogin or VM external IP constraints: control SSH and public exposure posture.
  • sql.restrictPublicIp: force Cloud SQL onto private IP from the start.
  • constraints/compute.vmExternalIpAccess: deny external IPs where workloads should be private.
  • storage uniform bucket-level access enforcement where applicable.

How to set:

gcloud resource-manager org-policies enable-enforce --organization [ORG-ID] [CONSTRAINT]

(list constraints with gcloud resource-manager org-policies list --organization [ORG-ID])

Traps:

  • Enforcing key-creation denial while your CI still uses keys breaks deploys instantly. Sequence: migrate auth, then enforce.
  • Folder-level policies inherit; test at a sandbox folder before org-wide enforcement.
  • Terraform googleorganizationpolicy resources exist; manage policies in the same IaC repo so the guardrails are versioned too.
  • Some constraints need the Org Policy API enabled and specific permissions (orgpolicy.policyAdmin).

Verify: attempt a violating create (e.g. mint a key) and confirm the policy denies it, then run the real apply and confirm zero violations in the policy analyzer.

Evidence

Verified 2026-09-26 on the org policy overview docs: constraint format (constraints/...), allow/deny/list semantics, inheritance, and the documented constraint examples. Enforcement-before-provisioning is the documented posture pattern.

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_XX91t-cryZxNOHkCtX_hzg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Org-policy-safe IaC: constraints to set before terraform apply in a fresh org <span>— Vectle</span></a>