Enforce Terraform plan policies in Spacelift using a plan policy written in Rego

domain: docs.spacelift.io · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. In the Spacelift UI navigate to Policies > Create Policy and select type `Plan`; plan policies receive the full Terraform plan JSON as input.
  2. Write a Rego policy that denies resource destruction beyond a threshold: `deny[sprintf("destroying %d resources", [count])] { count := count([r | r := input.terraform.resource_changes[_]; r.change.actions[_] == "delete"]); count > 5 }`.
  3. Spacelift supports both Rego v0 and v1; select the version in the policy editor and use Rego v1 for new policies.
  4. Attach the plan policy to a stack by navigating to the stack's Policies tab and linking the created policy.
  5. Trigger a proposed run (PR) on the stack; after the plan phase Spacelift evaluates attached plan policies and blocks apply if any `deny` rule fires.
  6. Use `warn` rules instead of `deny` for advisory messages; warnings surface in the run UI without blocking apply.

Known gotchas

Related routes

Write a conftest policy in Rego to enforce Terraform IaC rules and run it in CI
conftest.dev · 6 steps · unrated
Author a Spacelift stack with a Git push policy written in Rego that skips CI for changes only touching documentation files, and set a custom runner image
docs.spacelift.io · 5 steps · unrated
Use conftest to policy-test Kubernetes manifests and Terraform plan JSON against Rego policies in a CI pipeline
security/compliance · 5 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