Infrastructure as Code
The problem
Manually clicking through a cloud provider's console to create servers, networks, and databases is slow, error-prone, and impossible to reliably reproduce — infrastructure as code describes infrastructure declaratively in files, versioned and reviewed like application code, and applied automatically.
Why now
Package management already showed that a dependency graph can be resolved automatically rather than installed by hand in the right order; infrastructure as code applies that same declarative, dependency-aware approach to entire systems — servers, networks, and their relationships — using graph theory's topological ordering to decide what to create first.
Mental model
Infrastructure as code describes the desired end state of your infrastructure — 'a server, a database, a network connecting them' — as a dependency graph, and a tool computes a valid creation order (a topological sort, precisely) automatically, the same problem package managers and build systems already solve, just for cloud resources instead of software packages.
Requires
- Environment & ConfigurationLinux
Infrastructure as code externalizes configuration (server sizes, regions, counts) into version-controlled files, the same externalization principle already established for application configuration, applied one level up to the infrastructure itself.
- Graph Theory BasicsMathematical Thinking
An infrastructure-as-code tool resolves resource creation order by building and topologically sorting a dependency graph (a database must exist before a server that connects to it) — the exact algorithm already covered, applied to cloud resources.
Used in
- Terraform, Pulumi, and CloudFormation as the dominant infrastructure-as-code tools
- Reproducible environments — spinning up an identical staging environment from the same code that defines production
- Code review for infrastructure changes, catching mistakes before they're applied to real systems
- Disaster recovery, rebuilding an entire environment from code rather than manual reconstruction
Projects
- Write infrastructure-as-code (Terraform or similar) to provision a simple resource (a storage bucket, a virtual machine) and apply it, then modify and reapply to observe the tool compute only the necessary changes
- Diagram the dependency graph a real infrastructure-as-code file implies (e.g. a network before a server before a load balancer) and confirm it matches the tool's actual creation order
Examples
- Defining a database and a server that references its connection string, the IaC tool automatically creates the database first, inferring the dependency from the reference
- Reapplying the same infrastructure code twice produces no changes the second time — the declarative model computes only the diff needed to reach the desired state
Resources
Mastery checklist
- I can write basic infrastructure-as-code to provision a simple cloud resource
- I can explain why infrastructure as code determines resource creation order from a dependency graph
- I can explain the benefit of declarative (desired-state) infrastructure over imperative, manual provisioning
- I can review an infrastructure-as-code change and predict what it will actually change