Problem
Infrastructure created by clicking through consoles cannot be reproduced, reviewed or audited. Staging and production diverge, knowledge lives in individual heads, and disaster recovery means guessing what used to exist.
Also known as: iac, declarative-infrastructure
Define and provision infrastructure through version-controlled code so environments are reproducible, reviewable and testable.
Infrastructure created by clicking through consoles cannot be reproduced, reviewed or audited. Staging and production diverge, knowledge lives in individual heads, and disaster recovery means guessing what used to exist.
Infrastructure as code replaces manual provisioning with files that describe networks, clusters, databases and permissions. The same definitions create development, staging and production, which removes a large class of it-works-here bugs.
The workflow has three stages: write, plan, apply. The plan compares code against recorded state and the real provider, then lists creates, updates and destroys. A human or policy engine reviews it.
code --> plan --> review/policy --> apply --> state backend
^ |
+------ drift check (scheduled) ----+
A minimal resource looks like this:
resource "aws_s3_bucket" "logs" {
bucket = "acme-logs-prod"
}
State must live in a remote backend with locking so two applies cannot run concurrently.
Low - state storage and CI runners
Medium - module maintenance, upgrades, state hygiene
Medium - provider semantics and dependency graphs
Corrupted or concurrently modified state file
Apply destroys a stateful resource because of a rename
Console drift makes the next plan unexpectedly destructive