Git, CI/CD & GitOpsXLIX · Infrastructure CIInfrastructure CI
The infrastructure pipeline pattern — eight stages from commit to audit
What you'll learn
- Name the eight canonical stages of an infrastructure CI pipeline in order
- Explain why each stage exists as a separate gate and what failure mode it prevents
- Distinguish a static gate (format, lint, security) from a dynamic gate (plan, test, apply)
- Recognise why "single job that runs terraform apply" is not a pipeline
Prerequisites
Practice
Verified against Git 2.55.x teaching target; 2.40+ minimum · GitHub Actions continuous service; Aug 2026 documentation baseline · Argo CD v3.5.x teaching target; v3.0+ minimum · Flux v2.9.x · Sigstore Cosign v3.1.x · SLSA v1.2 · OCI Distribution Specification v1.1 · Git LFS v3.7.1 · Kubernetes (cross-course target) 1.36.x
Infrastructure CI is a pipeline, not a job. The most common
mistake teams make when adopting CI/CD for Terraform, Ansible,
or Kubernetes manifests is collapsing every check into a single
step that runs terraform apply. That single step produces no
useful signal: the apply either succeeds (and you learned
nothing about risk) or fails (and you learned about a syntax
error you could have caught at the format stage for free). The
eight-stage pipeline exists to spread feedback across time,
cost, and severity so that cheap checks happen first and
expensive checks happen only on changes that have already
passed the cheap ones.
The eight stages
The eight stages of an infrastructure CI pipeline, in the order they run, are: format, lint, security, tests, plan, review, apply, audit. Each stage is a separate job with its own runner, its own timeout, and its own success criterion. Failure at any stage halts the pipeline and surfaces a specific feedback signal.
flowchart LR
A["1. format"] --> B["2. lint"]
B --> C["3. security"]
C --> D["4. tests"]
D --> E["5. plan"]
E --> F["6. review"]
F --> G["7. apply"]
G --> H["8. audit"]
The order is deliberate:
- Format runs first because it is the cheapest (seconds) and catches the most common contributor mistake (inconsistent whitespace, misaligned blocks). Failing here wastes zero reviewer time.
- Lint runs next because it is still cheap and catches semantic-but-not-syntactic problems: unused variables, deprecated resources, missing tags.
- Security runs third because it is more expensive (it builds a graph of resources) but still static. A misconfigured S3 bucket or an open security group should never reach plan.
- Tests run fourth because they are dynamic — they provision real or simulated resources. Tests belong after static gates so a change that fails lint never spins up cloud resources.
- Plan runs fifth because it is the most expensive static operation: a full provider refresh against real APIs.
- Review is the human-in-the-loop stage: a reviewer examines the plan artefact, the security report, and the test report before approving.
- Apply runs only after review, with the exact plan that was reviewed.
- Audit runs after apply to record what actually happened against what was approved.
What each stage catches
A useful way to read the pipeline is “what does this stage prevent?”. The table below summarises:
| Stage | Catches | Cost |
|---|---|---|
| format | whitespace drift, unaligned blocks | seconds |
| lint | unused vars, deprecations, missing tags | seconds |
| security | open SG, public bucket, hardcoded secret | tens of seconds |
| tests | wrong module wiring, broken converge | minutes, may provision |
| plan | unintended resource replacement, drift | tens of seconds to minutes |
| review | intent mistakes the tools cannot see | human time |
| apply | nothing — only executes the approved plan | minutes, mutates state |
| audit | post-hoc divergence, compliance evidence | seconds |
Static gates versus dynamic gates
The first four stages are static: they read the source files and produce a verdict without contacting any external system. Format, lint, security scanning, and unit-level convention tests all fit here. Static gates are fast, deterministic, and safe to run on every push, including pull requests from forks.
The next two stages are dynamic: they contact external
systems. terraform plan calls the provider APIs and may
read state from a remote backend. Terratest provisions real
infrastructure (or mocks it via a local backend). Dynamic
gates are slower, may have side effects (refreshing state,
creating ephemeral resources), and are therefore gated
behind the static gates.
The last two stages are operational: review is human, apply mutates state, audit records. These stages are not “checks” in the same sense; they are the point of the pipeline.
Production discipline
Three rules govern how an infrastructure pipeline is constructed:
- Every stage is a separate job. Two stages that share
a runner share an environment, and an environment that
holds a
terraform applyis an environment that should not be holding atflintcache. - Every gate fails the build. A security warning that does not fail the build is not a gate; it is a log line. Decide whether the warning is a gate before you write the pipeline, not after the first false positive.
- The plan artefact is the review artefact. The exact bytes the reviewer approved are the bytes that are applied. Re-planning between review and apply is a re-review, not a re-run.
Cross-course references
- Ansible for Production Sysadmins — Part XXXVII (RepoArch) covers Ansible repository layout, which feeds the lint and test stages of an Ansible CI pipeline.
- Terraform for Production Sysadmins — Part XXV (QualityGates) covers the format, lint, and validate gates in depth; the plan and review stages are covered in Part XXVI (PlanReview).
- Kubernetes for Production Sysadmins — Parts XXX-XXXII cover manifest validation, the Kubernetes analogue of the static gates.
Quiz
Knowledge check · 4 questions
Q1. A team collapses their Terraform CI into one job that runs fmt, validate, and apply sequentially. Which operational property has been lost?
Q2. The format stage belongs before the lint stage because format failures are cheaper to detect than lint failures.
Q3. Name the four static gates in the eight-stage pipeline and give one example of what each catches.
Q4. Diagnose a pipeline that puts security scanning after the plan stage and propose the corrected order.
A team runs format, lint, plan, then security. The plan stage takes eight minutes because the Terraform configuration has eighty resources across three providers. Security runs after plan and flags an open security group on a database subnet. The engineer had to wait eight minutes before learning the change should never have been approved at all.
Passing score: 75%. Answers are checked in this browser.