Environment Provisioning and Infrastructure as Code
This domain tests whether environments are defined as versioned, reviewable code rather than as accumulated console history. Expect questions about state handling, drift, immutability and environment parity.
Declarative, idempotent, versioned
Infrastructure as code describes the desired state and lets the tool compute the diff; applying twice yields the same result. Networks, clusters, databases, DNS, IAM and bucket policies all belong in version control, reviewed by pull request like application code.
State is the risk surface
Terraform maps configuration to real resources through state. Store it remotely with locking (object store plus lock table, or a managed backend) so two pipeline runs cannot race and corrupt it. Never commit state to git - it often contains secrets - and never let two environments share one state file, because a plan then touches everything.
Immutable infrastructure
Replace servers instead of patching them: golden images built by Packer, containers with pinned digests. Immutability eliminates configuration drift and makes rollback a redeploy of a known image.
Parity and ephemeral environments
Environments use the same modules and only differ in size, scaling and secrets. Per-pull-request preview environments in a scoped namespace give reviewers and integration tests realistic infrastructure without long-lived pets.
Drift and guardrails
Scheduled plan runs detect manual console changes. Policy-as-code (OPA, Conftest, cloud organisation policies) rejects non-compliant resources at plan time, before anything is created.
Worked example
Staging and production diverge after an engineer adds a security group rule in the console. The next production plan shows one unexpected rule and the pipeline fails on drift. The team imports or reverts the rule, removes console write access via IAM, and moves both environments onto the same shared module with only instance_class and CIDR inputs differing. The failure is now impossible to reach production unnoticed.
Traps that cost marks
- Click-ops hotfixes that leave state authoritative but wrong.
- Secrets in committed
.tfvarsor plain-text variable files. - Assuming an apply that succeeded means the environment matches code - only a plan proves it.
- Long-lived environments patched differently each time, so no test result transfers to production.