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.
- 1The dev pipeline runs on every push and pull request. The prod pipeline only runs when started by hand.
- 2tfsec scans the Terraform code. A critical finding stops the pipeline before any plan is made.
- 3
terraform planis saved as an artifact. - 4Prod waits for an approval.
- 5
terraform applydeploys 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 initwith the backend config,terraform validate,terraform plan -out=tfplan, publishtfplanas an artifact. - ApplyDev / ApplyProd. A runOnce deployment job on the terraform-agents pool. Check out the code, download the
tfplanartifact,terraform initwith 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.