Prompt
How do I integrate IaC into CI/CD pipelines?
Latest observation
Oct 25, 2026
OpenAI APIWeb search: off
Integrating Infrastructure as Code (IaC) into CI/CD means treating infrastructure changes like application code: versioned, reviewed, tested, and deployed through automated pipelines.
Typical CI/CD flow for IaC
-
Developer makes an IaC change
- Example: modifies Terraform, CloudFormation, Pulumi, or Bicep files in a pull request.
-
CI validates the change
- Format/lint
- Static analysis/security scanning
- Plan/dry-run against target environment
- Policy checks
-
Review and approval
- Humans review the proposed infrastructure diff.
-
CD applies the change
- After approval/merge, the pipeline applies the infrastructure update.
Recommended pipeline stages
1) Source control
Store all IaC in Git:
- Separate repos or mono-repo, depending on your org
- Branching strategy with PRs
- Code owners for sensitive infrastructure
2) Validate on pull request
Run these checks automatically:
- Formatting:
terraform fmt,bicep format, etc. - Linting:
tflint,cfn-lint,checkov,terrascan - Syntax validation:
terraform validate - Security scanning: detect risky configs, open security groups, plaintext secrets
- Policy-as-code: OPA/Conftest, Sentinel, Azure Policy, AWS Config rules
3) Plan / preview
Generate a deployment preview:
- Terraform:
terraform plan - CloudFormation: change sets
- Pulumi:
pulumi preview
This lets reviewers see exactly what will change before approval.
4) Approve and apply
After approval:
- Apply only from the main branch or release branch
- Use environment-specific approvals for prod
- Require manual gate for high-risk changes
5) Post-deploy checks
- Verify resources exist and are healthy
- Run smoke tests
- Monitor logs/metrics/alerts
Example Terraform pipeline pattern
Pull request pipeline
terraform fmt -checkterraform initterraform validatetflintcheckovterraform plan -out=tfplan- Publish plan as artifact or comment it on the PR
Merge to main pipeline
- Download approved plan artifact or regenerate plan
- Manual approval for production
terraform apply tfplan
Key best practices
Use remote state
- Store state in a secure backend:
- AWS S3 + DynamoDB lock
- Azure Blob Storage
- GCS
- Never commit state files to Git
Separate environments
- Dev / staging / prod should be isolated
- Use separate state files or workspaces, or separate accounts/subscriptions/projects
Make deployments idempotent
- Pipelines should be safe to re-run
- Avoid manual changes in the cloud console
Protect secrets
- Use secret managers or pipeline secret stores
- Never hardcode credentials in IaC
- Prefer short-lived identities/OIDC over static keys
Add policy and security gates
- Prevent insecure defaults
- Enforce tagging, encryption, logging, and network rules
Promote artifacts, not just code
- If possible, use the same reviewed plan/artifact that was validated in CI
Common tools
- Terraform + GitHub Actions / GitLab CI / Jenkins / Azure DevOps
- CloudFormation + CodePipeline / GitHub Actions
- Pulumi + CI runners
- Atlantis for automated Terraform plan/apply on PRs
- Spacelift / Env0 / Terraform Cloud for managed IaC workflows
Simple architecture
- PR opened → validate, scan, plan
- PR approved → merge to main
- Main pipeline → apply to dev/staging
- Manual approval → apply to prod
- Post-deploy → smoke tests and monitoring
Example GitHub Actions sketch
name: iac
on:
pull_request:
push:
branches: [main]
jobs:
terraform:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform fmt
run: terraform fmt -check
- name: Terraform init
run: terraform init
- name: Terraform validate
run: terraform validate
- name: Terraform plan
run: terraform plan -out=tfplan
If you want, I can also give you:
- a Terraform + GitHub Actions end-to-end example,
- a best-practice pipeline design, or
- a version tailored to AWS / Azure / GCP.