Infrastructure as Code
Part of platform and delivery.
Question: how do you create and change environments so they can be re-created, reviewed, and kept consistent with each other?
The deployment principles state the core idea: represent infrastructure configuration as code and store it in source control, so environments can be re-created and the configuration is shared.
Declarative and imperative tools
Most of these are run as push: someone or a pipeline runs the apply step. GitOps adds continuous reconciliation.
State and drift
The declared state, the recorded state, and the real infrastructure can all differ. Drift appears when someone changes a resource by hand, when an apply fails partway, or when a provider changes defaults.
Run plan regularly, not only before changes, to detect drift. Decide whether to correct it in code or revert it.
Consistency across environments
The Kubernetes notes put the argument for consistency plainly: every difference between clusters makes the system harder to understand. Knowledge from one cluster stops transferring, and problems appear in some places and not others. Automate the creation of the environments themselves, not only the deployment of applications into them. See universalization.
This is the infrastructure side of Twelve-Factor’s dev/prod parity: environments close to the developer favor fast feedback, and environments close to production should match it. See environments.
Immutable infrastructure
Replace instead of patching: build a new image or instance and switch to it, rather than changing a running one. This extends Twelve-Factor’s build, release, run separation and the container principle of image immutability to infrastructure. See Twelve-Factor.
Modules, policy, and review
- Modules: reusable units, such as a standard service network or database setup, are infrastructure’s version of a golden path.
- Policy as code: rules such as “no public buckets” or “every resource has an owner tag” are checked automatically against the plan before apply. Chankramath et al. treat it as the basis for governance and compliance in a platform.
- Review: a plan output attached to a pull request shows reviewers what will change, not just what the code says.
- Tests and pipelines: Chankramath et al. (chapter 6) apply test-driven development and static code analysis to infrastructure code. They split infrastructure pipelines by level: account, control plane, and namespace.
In ML and AI systems
The MLOps notes list infrastructure as code for provisioning ML workloads. The AI design notes extend the same idea to the system definition itself; see GitOps applied to AI system configuration.
Learning it
See Terraform for practical learning advice: pick one concrete goal, do it once by hand or with the CLI, then express it as code.
Library sources
- Salatino 2024, Platform Engineering on Kubernetes – Crossplane and environment pipelines
- Chankramath et al. 2026, Effective Platform Engineering – policy as code, and infrastructure pipelines and tests
- Chapter notes: chapter 4 (policy as code with Open Policy Agent), chapter 6 (pipeline levels, choosing an IaC framework, testing infrastructure code)
Further reading:
- AWS 2024, AWS Well-Architected Framework