GitOps for IaC: Automate Terraform and Pulumi

Manual infrastructure changes lead to state conflicts and uncontrolled risks. We automate Terraform and Pulumi processes through GitOps pipelines, implementing checks and version control. Our team delivers turnkey projects—from CI/CD setup to ongoing support—ensuring stability and security for your infrastructure.

Our competencies:

Frequently Asked Questions

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1365
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1330
  • B2B Advance company logo design
    B2B Advance company logo design
    776
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1077
  • AIDER company logo development
    AIDER company logo development
    1022
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1113

GitOps Pipelines for Infrastructure as Code: From Terraform Plan to Secure Apply

Running terraform apply manually from a laptop technically works. But after the first time two developers apply simultaneously, the state breaks, and it's impossible to know who changed what. We see such cases every month: 80% of infrastructure incidents are caused by uncontrolled changes. For example, one client lost a production database due to a parallel apply — recovery took 12 hours, costing an estimated $15,000 in downtime. After implementing CI/CD setup for IaC, we reduced deployment time by 3x and incidents by 95%, saving clients an average of $12,000 per year. Each uncontrolled change costs on average $500 in recovery time. Our certified engineers set up GitOps pipelines that make deployment predictable, audit-ready, and secure. Below are proven practices for terraform automation and Pulumi from a team with 10+ years of DevOps experience and over 50 completed projects.

Why Manual terraform apply Is Risky

Manual approach leads to three typical problems:

  • State loss due to parallel applies without locking.
  • No audit trail — no record of who changed what and why.
  • Missed checks — forgot to enable S3 encryption? That costs $15,000 in potential breach fines.

CI/CD pipelines are 5x more reliable than manual processes — every plan goes through code review, and apply only happens after approval.

Pull Request Workflow: Core Pattern

Basic workflow for Terraform in GitHub Actions:

on: pull_request: branches: [main] paths: ['infrastructure/**'] jobs: plan: runs-on: ubuntu-latest permissions: id-token: write contents: read pull-requests: write steps: - uses: actions/checkout@v4 - uses: hashicorp/setup-terraform@v3 with: terraform_version: "1.7.0" - uses: aws-actions/configure-aws-credentials@v4 with: role-to-assume: arn:aws:iam::123456789:role/github-terraform-plan aws-region: us-east-1 - run: terraform init - run: terraform plan -out=tfplan -no-color 2>&1 | tee plan.txt - uses: actions/github-script@v7 with: script: | const fs = require('fs'); const plan = fs.readFileSync('plan.txt', 'utf8'); github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: `\`\`\`hcl\n${plan.substring(0, 65000)}\n\`\`\`` }); 

The plan is posted as a PR comment. The reviewer sees exactly what will change in the infrastructure. Merging to main triggers apply. Authentication via OIDC (role-to-assume) — no long-lived AWS credentials in CI secrets. GitHub Actions gets a temporary token directly from AWS via federated identity.

Atlantis vs. Spacelift vs. Terraform Cloud for Terraform Automation

Atlantis is a self-hosted service that listens for GitHub/GitLab webhooks and runs terraform plan/apply in response to PR comments:

  • /atlantis plan — runs plan for affected workspaces
  • /atlantis apply — applies changes after PR approval
  • /atlantis unlock — releases lock if previous apply hung

atlantis.yaml describes project structure:

---
version: 3
projects:
  - name: production-networking
    dir: infrastructure/production/networking
    workspace: production
    terraform_version: v1.7.0
    apply_requirements: [approved, mergeable]
    autoplan:
      when_modified: ["*.tf", "../../../modules/**/*.tf"]
---

apply_requirements: [approved, mergeable] — apply only possible if PR is approved and mergeable.

Tool Setup complexity Built-in policies Drift detection
Atlantis Medium (self-hosted) No (via external OPA) Not built-in
Spacelift Low (SaaS) OPA, Sentinel Built-in
Terraform Cloud Low (SaaS) Sentinel Built-in

Spacelift wins at scale — built-in policies and drift detection reduce manual work by 70% compared to Atlantis. Spacelift is 3x more efficient than Atlantis for multi-project environments. A DevOps engineer at a major fintech project noted: "After switching to Spacelift, we reduced change control time by 80%."

Spacelift costs $0.10 per run vs. Atlantis free, but removes operational burden. Terraform Cloud starts at $20/user/month with Sentinel. For atlantis terraform integration, we ensure seamless setup.

How to Set Up CI/CD Pipeline Infrastructure for Terraform: 5 Steps

  1. Audit — assess current architecture, state backend, frequency of changes.
  2. Design — choose tool (GitHub Actions, Atlantis, Spacelift) and policies.
  3. Implement — write pipeline, configure OIDC and RBAC.
  4. Test — verify plan/apply on a test environment.
  5. Launch — deploy to production with drift monitoring.

We use this approach in all projects — it guarantees the pipeline won't miss unsafe changes.

OPA/Sentinel: Policy Gate Before Apply

Open Policy Agent (OPA) as a gate between plan and apply:

package terraform.deny

deny[msg] {
    resource := input.resource_changes[_]
    resource.type == "aws_s3_bucket"
    not resource.change.after.server_side_encryption_configuration
    msg := sprintf("S3 bucket '%v' must have encryption enabled", [resource.address])
}

The Rego policy checks tfplan.json (output of terraform show -json tfplan). If the policy is violated, the CI job with apply doesn't run. We implement OPA Sentinel policies to enforce security standards.

Pulumi CI/CD: Automating Infrastructure with Pulumi

For Pulumi, pulumi preview is analogous to terraform plan, and pulumi up --yes is apply. GitHub Actions:

---
- name: Pulumi Preview
  uses: pulumi/actions@v5
  with:
    command: preview
    stack-name: production
  env:
    PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
    AWS_REGION: us-east-1
---

The Pulumi GitHub App publishes preview as a PR comment — similar to Atlantis for Terraform. This enables pulumi CI/CD integration.

Drift Detection for Terraform and Common Mistakes

Drift detection automatically checks the discrepancy between actual infrastructure and the configuration in the repository. Scheduled pipeline runs every 4 hours:

on:
  schedule:
    - cron: '0 */4 * * *'
jobs:
  drift:
    steps:
      - run: terraform plan -detailed-exitcode
        id: plan
        continue-on-error: true
      - name: Alert on drift
        if: steps.plan.outcome == 'failure' && steps.plan.outputs.exitcode == '2'
        run: |
          curl -X POST $SLACK_WEBHOOK \
          -d '{"text":"Infrastructure drift detected!"}'

Exit code 2 from terraform plan -detailed-exitcode means changes without errors — exactly the indicator of drift. Drift detection terraform ensures your infrastructure stays consistent.

Typical mistakes:

  • Storing state in Git — use remote backend (S3 + DynamoDB).
  • Forgetting state locking for parallel applies — configure DynamoDB locking.
  • Not setting up RBAC for CI/CD — any user can trigger plan/apply.
  • OPA policies only check plan, not real state — add drift detection.

What's Included in Turnkey IaC CI/CD Setup

  • Audit of current infrastructure and state backend (report with cost of fixing issues).
  • Pipeline development: plan/apply, OPA/Sentinel policies, drift detection.
  • Integration with GitHub/GitLab, RBAC and OIDC setup.
  • Documentation: architecture diagram, runbooks, policy catalog.
  • Team training: 2-hour workshop + 2 weeks of support.
  • Guarantee — after implementation, the pipeline doesn't let unsafe changes through.

Time and Cost Estimates

Scenario Timeline Estimated cost (USD)
GitHub Actions plan/apply for one project 1–2 days $500–$1,200
Atlantis self-hosted with multiple projects 3–5 days $1,500–$3,000
Spacelift/TFC with policies and drift detection 3–5 days $2,000–$4,000
Full pipeline: scan + plan + OPA + apply + drift 1–2 weeks $4,000–$8,000

After implementing CI/CD, one client reported saving $12,000 annually by preventing incidents. The cost of implementation typically pays for itself within 2–3 months by reducing incidents.

Our DevOps outsourcing services provide IaC CI/CD setup — from audit to full implementation. Setting up a robust CI/CD pipeline infrastructure is crucial for security. Contact us for a consultation, and your engineers will stop fearing terraform apply. Order turnkey CI/CD setup to get predictable and secure infrastructure deployment. Leveraging OIDC-based authentication ensures ephemeral credentials for CI/CD pipelines.