What is policy-as-code?

Definition

Policy-as-code is the practice of writing an organization’s security, cost, compliance and operational rules as version-controlled, machine-readable code - for example in OPA (Rego), HashiCorp Sentinel, or YAML/JSON - so they can be tested, reviewed and enforced automatically every time a change is proposed.

In short

Key takeaways.

  • 01

    Rules live in Git next to the infrastructure they govern, with history and review.

  • 02

    Evaluation is automatic and consistent: the same rule runs on every change.

  • 03

    Outcomes are explicit - allow, deny, or escalate to a human approver.

How it works

Policy-as-code, step by step.

  1. 01

    Write the rule

    Express a requirement - “no public storage”, “prod changes need approval”, “monthly cost under budget” - in a policy language.

  2. 02

    Version it

    Commit policies to Git so changes are reviewed and auditable.

  3. 03

    Evaluate on every change

    At plan, deploy, remediate and destroy, the proposed change is checked against applicable policies and context (environment, resource type, cost, tags).

  4. 04

    Decide

    The change is allowed, blocked, or escalated for human approval.

  5. 05

    Record

    The decision, the policy matched and the rationale are logged.

Why it matters

Manual reviews do not scale with cloud infrastructure or with autonomous agents. When software agents can make changes, policy-as-code is what keeps autonomy safe: it defines exactly what an agent may do, where, and under whose approval.

FAQ

Common questions about policy-as-code.

Common choices are Open Policy Agent’s Rego, HashiCorp Sentinel, and declarative YAML or JSON rule formats.

See it in practice

Watch Ana do it in your stack.

Thirty minutes, your systems, one real problem.