Free — no signup required

Introduction: Speed vs. Safety

2 min read

The DevOps Dilemma

Think of a construction site. You want workers to build fast, but you also need safety inspectors to ensure nobody skips load-bearing walls or uses substandard materials. In the old world, that inspector showed up at the end — after the building was half-finished. Policy as Code is the equivalent of embedding the inspector into the blueprint review process, before a single brick is laid.

We moved to Infrastructure as Code (IaC) to deploy faster. Developers can now spin up databases and servers in minutes. But this speed creates fear for security and operations teams:

  • What if a developer accidentally makes an S3 bucket public, exposing customer data?
  • What if they spin up an expensive GPU instance that blows the monthly budget?
  • What if they forget to tag resources, making cost attribution and compliance audits impossible?

In the old days, we had manual review boards. You'd submit a ticket, and someone would manually check your configurations. This is too slow for DevOps — a team shipping dozens of changes per day cannot wait 48 hours for a human reviewer.

Automated Guardrails

Policy as Code (PaC) is the solution. Just as we write code to define what infrastructure we want (Terraform), we now write code to define the rules that infrastructure must follow. Before the infrastructure is actually created, an automated engine checks your IaC code against your policy code.

  • IaC says: "Create a public S3 bucket."
  • Policy says: "S3 buckets must never be public."
  • Result: The deployment is automatically blocked before it happens.

This is called shifting left — moving security and compliance checks to the earliest possible stage in the development lifecycle, when fixing a problem costs minutes instead of days. A misconfiguration caught in a pull request takes 5 minutes to fix. The same misconfiguration caught after a data breach takes months and millions of dollars.

The three main tools in this space are Checkov (static analysis), OPA/Rego (general-purpose policy engine), and Sentinel (HashiCorp's enterprise-integrated engine). Each occupies a different point on the spectrum of simplicity versus flexibility.

Interview Tip

Interviewers often ask: "What's the difference between Policy as Code and just writing tests for your Terraform?" The key distinction is enforcement point and scope. Tests (like terraform test or Terratest) validate that your infrastructure behaves correctly after it's built. Policy as Code validates that your infrastructure configuration is compliant before it's built, and it enforces organizational rules that span across all teams — not just one module's correctness. PaC is governance; testing is correctness.

This is one of 18 chapters

Every chapter is free — Kubernetes, Terraform, SRE, distributed systems, and more — with fast daily review built in.

Sign up free