Insights · Platform Engineering

Infrastructure as code: the discipline that scales

TerraformAnsible

Key takeaway

Treat infrastructure as software: reviewed changes, plan previews, locked state, drift detection in CI. Consoles cannot be reviewed.

IaC exists to solve one problem Microsoft’s guidance names precisely: environment drift. Without it, every environment becomes a unique, unreproducible “snowflake” — configured by consoles and SSH sessions whose history lives in people’s memories. With it, “the team edits the source, not the target,” and the same code that builds staging builds production, “just as the same source code always generates the same binary.” Terraform’s own framing is the tool-grade version: “an infrastructure as code tool that lets you build, change, and version infrastructure safely and efficiently.”

Google’s SRE book supplies the institutional argument from the operations side: hand-crafted configurations accumulate what the automation chapter calls “a cholesterol of technical debt,” and the “inevitable lack of consistency leads to mistakes” — with config “bit rot” setting in the moment nobody can say what a server is for. Their answer (idempotent conformance checks running on a schedule) generalizes: consistency must be produced by a system, not enforced by vigilance.

The five properties that make it “code”

IaC is a discipline, and the tooling only matters if these five properties hold:

  1. Declarative source of truth. Files describe the desired state — the what — and the tool computes the diff from reality. Imperative scripts describe a path, not a destination, and can’t converge.
  2. Version control as the only door. Every environment change is a commit. If a change can be made in a console that bypasses the repository, the console is your real source of truth and the repository is decoration.
  3. Review with plan previews. The pull request carries the plan — exactly what will be created, changed, destroyed. Reviewers see infrastructure consequences before they exist, which is the entire reason infra review works at all.
  4. State as a managed artifact. The state file is “the bindings between objects in a remote system and resource instances declared in your configuration” (Terraform state docs) — it must live in a remote, locking, access-controlled backend. State in git is both a merge-conflict generator and, when it contains secrets, a leak; the docs say never.
  5. Tested and gated. Static analysis, policy checks, and (for serious estates) ephemeral environments that prove the code end-to-end — the same pipeline discipline as application code (the regulated CI/CD article covers the evidence trail).

Drift: detect it, don’t debate it

Drift is what happens between deployments: someone opens a port, scales a node, edits a secret by hand. The defense is mechanical:

  • Scheduled plan runs against production in read-only mode, alarming on any non-empty diff — the SRE book’s Prodtest idea (idempotent verification “every 15 minutes”) scaled to the estate.
  • Break-glass with a return path. Emergencies will require console changes; the discipline is that the next commit reconciles the code with what the emergency did — within hours, not “someday”.
  • Immutable over patched where possible: replace instances from images instead of mutating them, so drift has a shorter half-life (rebuild-don’t-patch applies to infrastructure too).

AWS’s operational-excellence design principle carries the framing that makes this palatable to executives: apply “the same engineering discipline that you use for application code to your entire environment” — with automation carrying guardrails (rate control, error thresholds, approvals) precisely to limit human error.

What the empirical studies found

The research record justifies every gate above, because IaC without discipline is demonstrably unsafe. The SLAC study’s numbers are the canonical citation: 46,600 security-smell occurrences across 50,323 Ansible and Chef scripts — including 7,849 hard-coded passwords — with practitioners validating the smells in most sampled cases (Rahman et al., ACM TOSEM). A 2025 taxonomy update catalogued 62 security-smell categories across seven IaC tools and found the smells “persist in GitHub projects for long periods” — weak detection tooling, not malice, is why (War et al., arXiv). The tooling has matured in response: polyglot detectors like GLITCH now find security and design smells across Ansible, Chef, Docker, Puppet and Terraform with strong precision (Saavedra et al., arXiv 2023), and policy scanners ship 750+ predefined checks — CIS benchmarks included — for CI (Checkov). The takeaway is not “IaC is dangerous”; it is “IaC is code, and code without review, scanning and gates ships its bugs to production — now at infrastructure scale.”

Modules as products

The composition unit matters at estate scale. A Terraform module is “a collection of resources that Terraform manages together” (modules docs) — but the operating model is what makes modules pay: standard structure, documented interfaces, version-pinned consumption, published to an internal registry. Treat modules as products with consumers: the network module, the database module, the secrets-integration module (vault wiring behind a stable interface). Copy-pasted HCL across twenty repos is the console problem back in text form — drift with better typography.

Rule of thumb

If your infrastructure can only be rebuilt by the people who built it, it isn’t coded yet. The test: a new engineer, the repository, and the pipeline — same environment, no interviews.

Put your infrastructure under discipline

Sources