Create a GCP Organization Policy custom constraint using CEL to restrict VM machine types

domain: cloud.google.com/resource-manager/docs/organization-policy · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Create a YAML file defining the custom constraint with fields: `name: organizations/<ORG_ID>/customConstraints/custom.restrictMachineType`, `resourceTypes: [compute.googleapis.com/Instance]`, `methodTypes: [CREATE, UPDATE]`, `condition: <CEL expression>`, `actionType: DENY`.
  2. Write a CEL condition such as `resource.machineType.contains('n1-standard') || resource.machineType.contains('e2-medium')` to deny non-compliant machine types.
  3. Deploy the custom constraint: `gcloud org-policies set-custom-constraint constraint.yaml`.
  4. Create an organization policy that references the constraint: `gcloud org-policies set-policy policy.yaml` where the policy YAML specifies `spec.rules[].enforce: true` and the constraint name.
  5. Test by attempting to create a VM with a disallowed machine type; the operation should return a `CONSTRAINT_VIOLATED` error.
  6. Propagation of new organization policies can take up to 15 minutes; allow time before running compliance tests.

Known gotchas

Related routes

Write a ValidatingAdmissionPolicy using CEL expressions to enforce resource limits
kubernetes.io · 5 steps · unrated
Configure OPA Gatekeeper with a ConstraintTemplate and Constraint to enforce that all Deployments have a specified owner label and block admission for non-compliant resources
open-policy-agent.github.io · 5 steps · unrated
Configure CircleCI's configuration policies (config-policy-management) to enforce organizational standards on pipeline YAML using OPA Rego policies evaluated server-side
CircleCI · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans