GC
← All work

Project 01 · Architecture

Terraform CI/CD on Azure DevOps

Two separate pipelines, one for dev and one for prod. Each scans the Terraform code with tfsec, builds a plan, saves it as an artifact, and then applies that exact plan.

Azure DevOps · Terraform · tfsec

Pipelines
Dev and prod, independent
Dev trigger
Push to main, pull requests
Prod trigger
Manual only
Agent pool
terraform-agents

The pipelines

Same stages, different triggers.

Azure DevOps · agent pool terraform-agentsStage 1 · PlanStage 2 · Applypasscritical findingapprovalPush · PRruns devManual runruns prod1tfsecsecurity scan?terraform plan-out=tfplanpipeline stopstfplanartifactterraform applythe saved plandevautoprodafter approval2345Azure DevOpsStage 1 · PlanStage 2 · ApplypassapprovalfailPush · PRruns devManual runruns prod1tfsecsecurity scan?terraform plan-out=tfplantfplanartifact3terraform applythe saved plan42pipeline stops5devautoprodafter approval
  1. 1The dev pipeline runs on every push and pull request. The prod pipeline only runs when started by hand.
  2. 2tfsec scans the Terraform code. A critical finding stops the pipeline before any plan is made.
  3. 3terraform plan is saved as an artifact.
  4. 4Prod waits for an approval.
  5. 5terraform apply deploys exactly the saved plan, so nothing changes between review and deploy.

Jobs

What each job runs.

  • SecurityScan. Check out the code, install tfsec, run the scan, publish the test results.
  • Plan. Check out the code, terraform init with the backend config, terraform validate, terraform plan -out=tfplan, publish tfplan as an artifact.
  • ApplyDev / ApplyProd. A runOnce deployment job on the terraform-agents pool. Check out the code, download the tfplan artifact, terraform init with the backend config, terraform apply tfplan.
  • Plan once, apply once. The apply stage uses the saved plan, so what gets deployed is exactly what was planned.