Contents
Why Infrastructure Changes Need Pipeline Discipline
A manual config change has three properties that make it an incident waiting to happen: it's unreviewed (the only reviewer is the person making it, at the moment of making it), untested (the test is production), and unrecorded (the record is whoever was in the room, until they're not). The pipeline fixes all three at once, because a pipeline change has the mirror-image properties:
- Recorded. The change is a commit; the diff of what it will do is the plan output; both are stored with a timestamp and an author.
- Gated. Lint and policy checks run before anyone looks at it, the plan is produced before anyone approves it, and the approval is explicit — a named human, not a mood.
- Repeatable. The same job that ran on Monday runs on Friday. The path to production doesn't depend on whose keyboard it came from.
The mental model shift is the important part: the plan output is the code review of infrastructure. "Approve the merge" means "I have read the exact diff of what will be created, modified, and destroyed, and I accept it." Without the plan, approval is a formality; with it, it's a decision.
The Pipeline Stages for Config Changes
Five stages, in order, each catching the failure class the previous one can't:
| Stage | Tools | What it catches |
|---|---|---|
| Lint / validate | tflint, checkov[4], ansible-lint, PSScriptAnalyzer | Style errors, template faults, policy violations (public subnets, missing encryption, wildcard principals) — before anything is interpreted |
| Plan as gate | terraform plan[3], ansible --check[5] | The actual diff: what will be created, modified, and destroyed. This is the reviewable unit of the change |
| Test | Module unit tests, ephemeral environments, integration checks | That the thing works, not just that it's valid — catch "valid config, broken behavior" before prod |
| Promote | Approval gates, environments | Human sign-off for prod, and ordering: dev → staging → prod, never skipping |
| Rollback | State revert, snapshots, reverse playbooks | The path when it breaks — defined in advance, not improvised during the incident |
Plan-as-gate is the heart of the pipeline, and the stage most manual estates are missing entirely. Lint catches syntax; the plan catches intent — the "oh, that will replace the database" that no linter will ever flag. A pipeline without a plan step is a fast way to make unreviewed changes; the plan is what makes the review real.
GitHub Actions vs. Azure DevOps
Two engines cover most estates, and the choice is usually made for you by where the repos and the identity live:
| GitHub Actions | Azure DevOps | |
|---|---|---|
| Triggers | Push, PR, schedule (cron), workflow_dispatch, external webhooks | Pipeline triggers, service hooks, schedules, manual runs |
| Secrets management | Encrypted repo/org secrets; OIDC federation to cloud providers for short-lived credentials | Variable groups, with native linkage to Azure Key Vault |
| Approval gates | Environment protection rules: required reviewers, optional wait period | Environments with manual validation and gate conditions |
| Artifacts | Workflow artifacts, releases | Pipeline artifacts and feeds, with longer-retention options |
| Where it fits | Repos live in GitHub; internal or public; simple YAML, low ceremony | Azure-heavy estates; AD identity integration; on-prem agent hosts; compliance reporting |
Both do the same five jobs — lint, plan, test, approve, apply — and both support OIDC (OpenID Connect) for cloud credentials, which is the part that matters most for security: instead of storing a cloud access key in the pipeline, the pipeline proves its own identity to the cloud provider at run time and receives a credential that expires when the job ends. The practical rule: run the pipeline where the repo and the team already are. A mixed estate commonly runs Actions[1] for the GitHub-hosted repos and Azure DevOps[2] for the Azure-centric ones; what you don't want is the same repo piped through both engines, because then you have two review paths for one change and nobody knows which one is authoritative.
Environment Promotion Patterns
Three shapes, in increasing order of discipline:
- Branch per environment. dev/staging/prod branches, each applied to its environment. The simplest to set up and the most failure-prone in operation: the branches are copies, and copies drift. Prod ends up running code that isn't in main, and the "fix" becomes a merge whose plan nobody wants to read. If you do this, treat main as the only source and the environment branches as short-lived.
- Tag-based promotion. main is the trunk; a tag is the promotion unit. Dev applies the latest main; staging and prod apply the tagged version. The tag is the auditable artifact — "prod is running tag 2026.08.14" is a statement you can verify. This is the shape most infra estates land on.
- PR-based. A PR to main produces the plan and gets the review; merge promotes to dev automatically; a label or tag (with an approval gate) promotes to prod. This is the GitOps-adjacent pattern, and it's where the plan gate does its best work — the reviewer reads the plan in the PR, before anything runs.
Two additions make any of the three patterns honest. First, ephemeral test environments: one environment per PR, built by the pipeline, torn down on merge. This catches the class of failure that a shared staging env can't — behavior that depends on environment-specific config and only shows up when the environment is actually built from the PR's code. Second, drift checks in CI: a scheduled job that runs plan against the prod state with no code changes. A non-empty plan means something changed prod outside the pipeline — drift, detected on a schedule, with the diff attached. Drift stops being a discovery during an audit and becomes a weekly signal on a channel.
A Worked Example: A Terraform Module Pipeline
Here is the shape of a pipeline for a Terraform module — a plan gate on every PR, and an apply on merge that sits behind a manual approval in the prod environment. The specifics (module layout, roles) are yours; the structure is the standard one, and it's short enough to maintain.
# .github/workflows/terraform-module.yaml
name: terraform-module
on:
pull_request: # plan on every PR — the gate before merge
branches: [main]
push: # apply after merge, behind manual approval
branches: [main]
jobs:
plan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
- name: Lint
run: tflint --config=.tflint.hcl infrastructure/
- name: Init (no backend for the PR plan)
run: terraform -chdir=infrastructure init -backend=false
- name: Plan
id: plan
run: terraform -chdir=infrastructure plan -out=tfplan
- name: Publish plan for review
if: github.event_name == 'pull_request'
run: |
terraform -chdir=infrastructure show -json tfplan > plan.json
echo "Plan artifact: plan.json"
apply:
needs: plan
if: github.event_name == 'push'
runs-on: ubuntu-latest
environment: production # protection rule: manual approval required
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
# OIDC: the job assumes a short-lived role — no long-lived
# keys in the repo or in secret stores to rotate.
- name: AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/tf-apply-prod
aws-region: us-east-1
- name: Init and apply
run: |
terraform -chdir=infrastructure init
terraform -chdir=infrastructure apply -auto-approve
Three things to notice. The plan job needs no cloud write credentials at all — it's read plus state access, which is a meaningful reduction in what a PR-triggered job can do. The apply job is the only one that holds mutation rights, and it holds them for the duration of one job, assumed via OIDC. And the approval lives in the environment protection rule, so the gate is enforced by the platform, not by the convention that someone remembers to check the plan. If the plan in the PR and the plan at apply time can differ (they can, if prod state moved between the two), that's the scheduled drift job's job to surface.
Secrets and Credentials in Pipelines
The pipeline's credential model determines its security, and the model has one good shape and several bad ones:
- Short-lived, assumed — never stored. OIDC federation (the pipeline assumes a cloud role) or workload identity (the pipeline authenticates to the cloud with its own identity). The credential lives for the job, then it's gone. A long-lived key in a secret store is a stored password for a machine; an assumed role is a ticket that expires in an hour.
- Scope by stage. The plan job's role reads and touches state; the apply job's role adds mutation. A PR — which anyone with repo access can open — should never be able to trigger a job that holds prod write rights. The split is the control.
- What stays in the secret store. The oddities that don't fit OIDC: API tokens for third-party services, registry passwords where no SSO exists. Keep that list short, because it's the list of things you'll rotate by hand. And nothing that's a cloud credential, which is the category OIDC covers.
- Log hygiene. Mask secrets in the runner configuration, and never print state files or plans that may contain sensitive values. A plan that logs a database password has made the secret public to everyone with log access, which is usually more people than you'd like.
Pin and check your pipeline components like dependencies. Action versions, provider CLI versions, and OIDC role trust policies all evolve — a workflow that pins nothing drifts silently, and a role trust policy that's too broad (accepting any workflow, any branch) turns "short-lived credential" back into "anyone with repo access holds prod rights." Confirm the current supported versions and the exact OIDC trust conditions for your provider before you wire the first apply job, and re-check when you update the workflow.
Rollback, Specifically
"Rollback" means different things on each stack, and the pipeline's job is to make the right one cheap. The rule that unifies them: the unit of rollback is the unit of the commit — small, atomic commits give you small, clean rollbacks; a commit that changes the network, the database, and the firewall is a rollback you improvise during the incident.
- Kubernetes. Revert the Git commit and let the reconciler put the previous state back on its own — the reconciler being the controller running inside the cluster that continuously compares what is actually deployed against what the repository says should be deployed, and re-applies the difference. kubectl rollout undo exists as a bridge during the incident, not as the record — the record is the Git revert, which has an author and a review. That GitOps loop, where you edit the repository and the cluster follows it, makes this the cheapest rollback in the estate.
- IaaS (Terraform). Revert the commit and apply — but state is the wrinkle. A failed apply may have left partial state, and a resource destroyed by the bad change isn't restored by reverting the commit; it's restored by re-creating it, which the apply does. For data stores (databases, disks), config rollback and data rollback are separate paths: the config reverts, the data comes back from the snapshot taken before the apply. The snapshot before every prod apply is the data-plane half of the rollback story.
- Windows config. Re-apply the baseline from the config repo — the reverse playbook, or the full baseline run. For GPOs, versioned GPOs with a known-good generation to restore. The honest caveat: some Windows config isn't cleanly reversible — a deleted AD object is gone, and the "rollback" is a restore from backup with all the downtime that implies. This is precisely why the plan gate and the pre-apply snapshot exist: the reversible path should be the only path you ever need.
When a Pipeline Is Overkill
A pipeline is maintenance: it has workflows to keep current, runners to keep patched, secrets to keep scoped, and a path that can break in ways the manual path couldn't. For a small team with low change volume, the overhead can exceed the benefit, and the honest alternatives are:
- A script with a plan step and a review. For a team making a couple of config changes a week, "run plan, paste the output into the channel, a second person says yes, run apply" captures most of the safety for a fraction of the machinery. It's a process, not a platform — and at that volume, that's the right size of control.
- Git plus a scheduled apply, no engine. For estates that are effectively config-as-data, a repo with a reviewed merge and a job that applies on merge (no approval ceremony, because the review happened at merge) is often enough. The review is the gate; the pipeline just executes.
Rule of Thumb: A pipeline starts paying for itself at roughly three to five config changes per week, or the first time a config change caused a real incident — whichever comes first. The measurable payoff is two numbers you can only read if you start tracking them before you build: change-failure rate (the share of changes that require a fix or rollback) and MTTR — mean time to restore, the clock from "this config change broke something" to "the service is working again" — for config-caused incidents. Teams that instrument first and pipeline second can show the delta; teams that pipeline first can show the pipeline, which is not the same thing.
Measure change volume, failures, and recovery time. Add a reviewed plan gate, then introduce promotion and approval controls where risk, separation of duties, or change volume requires them. Keep the pipeline proportional to the environment and verify that each control catches a defined failure mode.
References
- GitHub — "GitHub Actions documentation": workflows, environments and protection rules, artifacts, and OIDC-based cloud authentication. GitHub Documentation, current.
- Microsoft — "Azure Pipelines documentation": YAML pipelines, variable groups with Azure Key Vault integration, environments, and manual validation gates. Microsoft Learn, current.
- HashiCorp — "Terraform CLI documentation": init, plan, and apply, plan files, and state management. HashiCorp Documentation, current.
- Prisma — "checkov documentation": policy-as-code scanning of infrastructure as code for misconfiguration and compliance. Prisma Documentation, current.
- Ansible — "Ansible documentation": the --check mode for dry-run validation of playbook changes. Ansible Project Documentation, current.