Spec-driven platform engineering: why your Terraform is not your spec

Your team, or its AI assistant, can now produce a week of infrastructure code in an afternoon. The question is no longer how fast you can write it. It is how you know the result does what you meant, and nothing more.

Spec-driven platform engineering means writing a short spec before anyone changes your infrastructure: what the change is for, what limits it must respect, and how you will check it worked. Engineers and AI agents then write the Terraform, Kubernetes and pipeline changes, and automatic checks hold them to the spec. The code describes the result. The spec describes the intent, and only the intent can tell you whether the result is right.

Where the idea comes from

Spec-driven development is the name software teams gave to a simple discipline that became urgent with AI coding assistants: write down what you want in a structured way first, then let people or agents generate code that matches it. Tools such as GitHub Spec Kit and AWS Kiro are built around it. An overview on martinfowler.com separates three levels: the spec guides one task (spec-first), the spec is kept and maintained afterwards (spec-anchored), or only the spec is edited and the code is regenerated from it (spec-as-source).

Almost everything written about it is about application features. Infrastructure has been left out, mostly because of one objection.

“Infrastructure as code is already a spec”

The objection goes like this: Terraform, Helm charts and Kubernetes manifests are declarative. You describe the desired state and the tool makes it so. Isn’t that a spec?

Partly. A Terraform file is a precise description of what should exist: this database, this size, this subnet. It is silent on everything a reviewer actually needs to judge a change:

  • Why the change exists. “Add a replica” is code. “Stop reporting queries from slowing down checkout” is intent, and it decides whether a replica is even the right fix.
  • Within what limits. Region and data residency, cost ceiling, what must not be touched, how much can break if this goes wrong.
  • How you would know it worked. Which number moves, by how much, and what alert tells you it stopped working.
  • How to undo it. Written before the change, while everyone is calm.

When a senior engineer wrote every line by hand, most of this lived in their head and in the pull request conversation. That worked, slowly. It works much less well when an AI agent produces two hundred lines of plausible Terraform in a minute and the reviewer has to infer the intent from the code.

Why it matters now

Coding agents do exactly what they are asked, and they fill every gap with a guess. In application code a wrong guess usually breaks a test. In infrastructure a wrong guess often works: the resource comes up, the pipeline is green, and the cost, the security exposure or the missing alert shows up weeks later.

The usual pattern is quiet over-provisioning and quiet scope creep. You asked for a queue and you got a queue, a dead-letter queue, a new IAM role with broader rights than needed and a log group that keeps everything forever. Each part is defensible. Nobody decided on the total.

A spec turns those guesses into decisions made in advance. It is the part of the change that a human owns.

What goes in an infrastructure spec

Keep it to one page in plain markdown, next to the code it governs. Six headings cover almost every change:

  1. Intent. One or two sentences on the outcome, in business terms.
  2. Constraints. Regions, data residency, cost limit, things that must not change, security boundaries.
  3. Done when. Measurable checks: a metric, a latency target, an alert that exists, a plan that only adds resources.
  4. Blast radius. What depends on the thing being changed, and what breaks if the change fails halfway.
  5. Rollback. The exact steps to undo it, and whether any data makes that hard.
  6. Out of scope. What this change deliberately does not do, so nobody, human or agent, does it anyway.

An example: a read replica for reporting

A short, realistic spec, of the kind we would write with a client:

# Spec: read replica for reporting

## Intent
Reporting queries stop slowing down checkout at peak.
Dashboards read from a replica; the application keeps the primary.

## Constraints
- EU region only: customer data stays in the EU
- Replica no larger than the current primary
- No change to the primary's size, parameters or maintenance window
- Read-only; no application traffic routed to it

## Done when
- The BI tool's connection points at the replica
- Replica lag under 60 seconds at the daily peak, with an alert if not
- Checkout p95 latency at peak back inside its SLO for a full week
- terraform plan shows additions only: no replacements, no deletions

## Blast radius
Primary unaffected if creation fails. Dashboards show stale data
if lag grows; that is acceptable for up to one hour.

## Rollback
Point the BI tool back at the primary, then destroy the replica.
No data to migrate.

## Out of scope
Moving reporting to a data warehouse. Separate decision.

Notice what it does. A reviewer can now reject a plan that resizes the primary, even if the code is clean. An agent asked to “implement this spec” has much less room to improvise. And six months later, someone wondering why the replica exists finds the answer next to it.

Turning the spec into checks

A spec that nobody enforces drifts from reality like any document. The trick is to make most lines testable in the pipeline that already runs on every pull request:

Spec lineEnforced by
EU region onlyA policy-as-code rule (OPA/Conftest) run against the plan output
Additions only, nothing replacedA pipeline step that reads terraform show -json and fails on delete or replace actions
Replica no larger than primaryThe same policy check, comparing instance classes
Cost within the limitA cost estimate posted on the pull request and compared with the agreed ceiling
Lag alert existsThe alert is defined in the same change, so the review sees it
Checkout SLO for a weekChecked after rollout on the existing SLO dashboard

Some lines stay human: the rollback steps, the blast radius, the “out of scope”. That is fine. The point is that the reviewer checks the change against a written intent and not against their memory.

The loop

In practice the workflow is short:

  1. Write the spec in the repository, as part of the pull request or before it.
  2. Generate or write the code, by hand or with an agent that is given the spec as its brief.
  3. Run the checks on the plan: policy, cost, destructive actions.
  4. Review the change against the spec. The question becomes “does this do what we wrote down?”
  5. Apply and verify the “done when” items.
  6. Keep the spec next to the code and update it when the intent changes. This is the spec-anchored level, and it is where most of the long-term value is: drift detection now has something to compare against besides the last apply.

When this is overkill

Not every change needs a spec. Bumping a version, adding a DNS record or rotating a secret is covered by the code and a normal review. During an incident, you fix first and write things down afterwards. And for a throwaway experiment in a sandbox account, a spec is ceremony.

It is also not a substitute for a platform. If every team writes its own specs for the same kind of change, you have found a golden path waiting to be built: a template where the spec, the module and the checks come together. That is usually the next step.

How to start this month

  • Pick one repository where infrastructure changes are frequent or risky.
  • Add a SPEC.md template with the six headings and require it for changes that add resources or touch production data.
  • Turn two lines into automatic checks first: “no destructive actions without approval” and “allowed regions”. They catch the most expensive surprises.
  • If your team uses AI assistants, give them the spec as their brief and ask for the plan output in the pull request.
  • After a month, look at which spec lines were violated or ignored. Those are your next checks.

FAQ

What is spec-driven development for infrastructure?

It is the practice of writing a short, structured spec before changing infrastructure: intent, constraints, success checks, blast radius and rollback. Engineers or AI agents then write the Terraform or Kubernetes changes, and automatic checks in the pipeline hold the change to the spec.

Isn’t Terraform already a spec?

Terraform describes the desired state of resources. It does not describe why they exist, what limits they must respect or how to tell whether the change worked. The spec adds those, and the checks connect the two.

How is this different from policy as code?

Policy as code enforces rules that apply to every change, such as allowed regions or required tags. A spec describes one change and its intent. In practice the spec reuses existing policies and adds a few checks of its own.

Does it work with GitHub Spec Kit or Kiro?

Yes. Both are designed around a spec, plan and tasks flow, and they work with infrastructure code as well as application code. The tool matters less than having specs that are kept in the repository and checked in the pipeline.

How we work on it

We help teams set this up as part of building their internal developer platform: spec templates, policy checks and golden paths that both people and AI agents can follow. When the urgent part is the code itself, we start with the Kubernetes and infrastructure as code work and add the specs as we go.

Tell us what's broken.

A few sentences is enough. We reply within one working day and the first call is free.