Skip to content

Part 6 · Infrastructure as Code

By now you can build an image, schedule it on Kubernetes, and ship it through a pipeline. But all of that has to run somewhere — on virtual machines, networks, load balancers, databases, DNS records, and IAM roles that someone has to create first. This Part is about how you create that “somewhere” — and the answer is the same answer this whole book keeps arriving at: stop doing it by hand.

The problem: ClickOps doesn’t scale or reproduce

Section titled “The problem: ClickOps doesn’t scale or reproduce”

The default way to build cloud infrastructure is to open the provider’s web console and click. Spin up a VM, attach a disk, open a firewall port, point a DNS record. It works, it’s fast, and it is a trap.

ClickOps Infrastructure as Code
─────────────────────────────── ───────────────────────────────
console → click → click → click edit file → commit → apply
knowledge lives in one person's head knowledge lives in a repo
"how did we build staging?" → shrug "how?" → read the .tf files
prod and staging quietly diverge both built from the same code
disaster recovery = rebuild by memory disaster recovery = re-apply

Click your way to a working environment and you have created something nobody can reproduce. There’s no record of what you did or why. Staging was built last March by someone who has since left; prod was built differently; the two have drifted apart and now a bug only happens in prod. When the region goes down, rebuilding means remembering — under pressure — every checkbox you ever ticked. The manual, error-prone step here isn’t one click. It’s the entire act of constructing infrastructure from human memory.

Infrastructure as Code (IaC) means you describe your infrastructure in plain-text files, commit them to version control, and let a tool make reality match the files. A VM is no longer a thing you clicked into being — it’s a few lines of code, reviewed in a pull request, applied by a pipeline, and rebuildable on demand. The infrastructure becomes a deterministic function of a repo: same code in, same infrastructure out.

This unlocks everything Git already gave your application code — review, history, blame, rollback, branching — and points it at servers and networks. It’s the same move CI/CD made for deployment, and the same move GitOps made for cluster state, now applied one layer lower: the platform itself.

We build the idea bottom-up, each page using only what came before:

  • Why Infrastructure as Code — the concrete payoffs: reproducibility, version control, review, drift elimination, and disaster recovery. Why infra you can rebuild from a repo changes how you operate.
  • Declarative vs Imperative — the central design choice. Scripting steps versus describing the end-state and letting a reconciler converge on it — the same control loop you met in Kubernetes.
  • Terraform — the dominant declarative provisioning tool: providers, resources, HCL, plan/apply, the dependency graph, variables, outputs, and modules.
  • State & Drift — the state file (what it is and why it must exist), remote state with locking, and how plan becomes a diff between your code and the real world.
  • Configuration Management (Ansible) — provisioning a server versus configuring what runs on it; idempotent, push-based playbooks, and how that differs from Terraform.
  • Immutable Infrastructure — the endgame: cattle not pets, golden images, rebuild instead of patch, and why immutability kills config drift for good. It ties straight back to why containers exist.

By the end you’ll see infrastructure the way you already see code: something you write, review, version, and can throw away and recreate without fear. Start with Why Infrastructure as Code.

  1. What does “ClickOps” mean, and name two specific problems it creates the moment more than one person or more than one environment is involved.
  2. In one sentence, what does Infrastructure as Code actually do — what becomes text, and what makes reality match that text?
  3. IaC is described as making infrastructure “a deterministic function of a repo.” Unpack that phrase: what goes in, what comes out, and why is determinism valuable?
  4. Which capabilities that Git already gives application code does IaC extend to servers and networks?
  5. Using the book’s recurring thread, state the single manual step IaC removes and the production-safety property it provides in return.
Show answers
  1. ClickOps is managing infrastructure by clicking through a cloud console by hand. The moment more than one person or environment is involved, two problems appear: the knowledge of how it was built lives only in someone’s head (so “how did we build staging?” gets a shrug), and prod and staging quietly drift apart because they were clicked together differently.
  2. IaC describes infrastructure in plain-text files committed to version control, and lets a tool make the real world match those files. The infrastructure becomes the text; a reconciling tool (run by apply) makes reality match it.
  3. A “deterministic function of a repo” means the repo is the input and the running infrastructure is the output: same code in, same infrastructure out. Determinism is valuable because it makes environments reproducible — you can rebuild staging or prod identically, on demand, instead of relying on memory.
  4. The same ones Git gives application code: review (changes as pull-request diffs), history/blame (“who changed this and when?”), rollback/revert, and branching to experiment safely.
  5. The manual step removed is building and changing infrastructure from human memory and clicks. In return production becomes rebuildable, reviewable, and identical to staging — every time — which is the safety dividend.