Skip to main content
Cloud DevOps Solutions
Get a quote Talk to an engineer

Terraform / IaC

Terraform Pull Request Automation with Atlantis or Terraform Cloud

We set up Atlantis or HCP Terraform (Terraform Cloud) so every infrastructure change is a pull request that shows its plan, needs approval, and applies from the pipeline after merge. Nobody applies from a laptop, and every change has a reviewer and an audit trail.

Key takeaways

  • The plan a reviewer approves must be the plan that runs, which is the core guarantee of this workflow.
  • Atlantis is self-hosted and free; HCP Terraform is managed and adds policy, run history and a UI at a price.
  • Plain GitHub Actions or GitLab CI is a legitimate third option, with more assembly required.
  • Credentials belong to the pipeline, using short-lived federation rather than stored keys.
  • Locking per project stops two pull requests from planning against the same state at once.

Why infrastructure changes need a pipeline

Application code usually passes through review and CI. Infrastructure code often does not. An engineer runs terraform apply from a laptop with broad credentials, the plan scrolls past in a terminal, and nobody else sees what changed. That works until the day it deletes a database, or until an auditor asks who changed the security group and why.

A Terraform CI/CD pipeline with plan on pull request and apply on merge fixes this. The plan becomes a visible, reviewable artefact, and the apply becomes an auditable event. It is one of the highest-value pieces of our Terraform and infrastructure as code service.

What good looks like

  • Opening a pull request automatically produces a plan, posted as a comment.
  • A named reviewer approves the code and the plan.
  • Applying happens from the pipeline using scoped, short-lived credentials.
  • The plan that was reviewed is the plan that is applied, or the apply is rejected if state has changed.
  • Only one change per state runs at a time.
  • Every apply is traceable to a pull request, an author and an approver.

The three realistic options

Atlantis

Atlantis is a self-hosted service. It receives webhooks from GitHub, GitLab, Bitbucket or Azure Repos, runs Terraform in a working directory, and comments the result. Its strengths are low cost, full control and plain configuration in a repository file. Its costs are that you run and secure it, and you scale it yourself.

HCP Terraform (Terraform Cloud)

A managed service with remote runs, state storage, run history, a UI, team permissions and policy checks. It removes the operations burden at the price of a vendor dependency and licensing that scales with usage. Check current pricing and terms before committing, as they change.

Plain CI (GitHub Actions or GitLab CI)

If you already live in one CI system, a workflow can do plan on pull request and apply on merge. You assemble locking, plan artefacts and comment formatting yourself. For teams with a single repository and a few stacks this is often enough. Our wider CI/CD pipeline service covers the principles.

ConcernAtlantisHCP TerraformPlain CI
HostingYou run itManagedYour CI runners
Cost modelCompute onlyUsage based licenceCI minutes
Plan comments on PRBuilt inBuilt inYou script it
LockingPer projectPer workspaceYou design it
UI and run historyMinimalRichCI logs
Best forCost control, self-hostingLess operational workSmall estates

How it works in practice

An Atlantis repository config

Projects declare where they live, which Terraform version to use, and what triggers a plan:

version: 3
automerge: false
projects:
  - name: prod-network
    dir: environments/prod/network
    terraform_version: v1.9.8
    autoplan:
      when_modified: ["*.tf", "../../../modules/network/**/*.tf"]
      enabled: true
    apply_requirements: [approved, mergeable]
workflows: {}

The apply_requirements line is the important one: nothing applies without an approval and a mergeable pull request. Watching module paths in when_modified ensures a module change re-plans every stack that uses it.

Credentials without stored keys

On GitHub Actions, the job assumes an AWS role through OIDC, so no long-lived keys exist to leak:

permissions:
  id-token: write
  contents: read
steps:
  - uses: aws-actions/configure-aws-credentials@v4
    with:
      role-to-assume: arn:aws:iam::123456789012:role/terraform-plan-dev
      aws-region: eu-west-1

The role ARN above uses a placeholder account number. Plan roles are read-mostly; apply roles are separate and only assumable from the protected branch or an approved environment.

Decisions and trade-offs

Apply before or after merge. Applying after merge is simpler and keeps main authoritative. Applying before merge catches failures early but can leave open pull requests holding a lock. We choose per team and write the rule down.

Autoplan everywhere or on demand. Autoplan on every push gives fast feedback but costs runner time in large monorepos. Path filters keep it sensible.

Policy as code. Adding checks to the pipeline is where Terraform security scanning fits, and cost estimation tools can sit alongside.

When not to build this yet. A solo engineer with one small stack and no compliance needs may be fine applying locally with remote state. The pipeline earns its keep when there are several contributors or any production risk.

Failure modes we avoid

  • Stale plans applied. We require the apply to match the reviewed plan or re-plan.
  • Lock left by a cancelled run. The runbook covers safe release.
  • Over-privileged pipeline role. One admin role for everything turns a pipeline compromise into an account compromise. We split by environment and by plan versus apply.
  • Fork pull requests running plans. Untrusted code could read credentials, so forks are blocked.
  • Plan output leaking secrets. Sensitive values are marked and comments are limited to what reviewers need.

Choosing by team shape

The right tool often follows who will own it. A platform team that already runs Kubernetes and is comfortable operating a small service tends to prefer Atlantis, because the running cost is low and the behaviour is transparent. A team with no appetite for operating anything, or one that needs run history and role-based permissions for auditors, usually does better with HCP Terraform. A team of three engineers with a single repository often needs neither, and a well-written workflow is the honest answer. We say so in the recommendation, even when it means less work for us.

A second question is blast radius. Whichever tool you pick, split state so that one pipeline run can only touch one environment or one component. A single giant state turns every pull request into a queue.

Delivery and handover

You receive a running pipeline, configuration in your repository, a contributor guide with example pull requests, and an operations runbook. We usually onboard one stack first, then expand. See the layout it fits into in our page on multi-environment setup.

How to tell it is working

Every production change links to a pull request. Local applies stop happening, which you can verify from cloud audit logs. Plans appear within minutes of opening a pull request, and review comments focus on the infrastructure, not on how to run Terraform. To choose between the options for your team, book a consultation.

References

How we deliver it

  1. 01

    Pick the tool

    We compare Atlantis, HCP Terraform and plain CI against your size, compliance needs, repository host and appetite for running another service.

  2. 02

    Stand it up securely

    Atlantis runs on your own compute with a locked-down webhook and a scoped role; HCP Terraform is connected through your VCS and workspace settings.

  3. 03

    Define projects and workflows

    Each stack becomes a project with its own directory, Terraform version, autoplan triggers and approval rules.

  4. 04

    Add checks to the plan stage

    Formatting, validation, linting and security scans run alongside the plan so reviewers see one result.

  5. 05

    Set apply rules

    Production requires approval and a mergeable pull request; dev may apply with fewer gates.

  6. 06

    Document and hand over

    You get a contributor guide, an operations runbook and a walkthrough of failure cases such as stuck locks.

Tools and technologies

AtlantisHCP TerraformTerraformOpenTofuGitHub ActionsGitLab CIGitHub OIDCCheckovtflintInfracostOpen Policy Agent

Frequently asked questions

What is Atlantis for Terraform?
Atlantis is an open source server that listens to pull request webhooks and runs Terraform for you. It comments the plan on the pull request, and applies it when someone comments atlantis apply after approval. It keeps a lock per project so two changes cannot collide, and it logs who did what.
Atlantis or Terraform Cloud, which should we choose?
Choose Atlantis if you want to self-host, keep cost low and keep runs inside your network. Choose HCP Terraform if you prefer a managed service with a UI, run history, policy checks and remote state included, and accept a per-resource price. Both give plan on pull request and controlled apply.
Can we do this with just GitHub Actions?
Yes. A workflow that runs plan on pull request and apply on merge works well, especially with OIDC credentials and environment protection rules. The trade-off is that you build locking, plan storage and comment formatting yourself. We help teams that prefer to stay on a single CI system.
Should apply happen before or after merge?
Both patterns exist. Apply after merge keeps the main branch as the single truth and is simplest to reason about. Apply before merge, which Atlantis supports, catches failures before they reach main but leaves a gap if a pull request is abandoned. We pick one per team and enforce it.
How do you stop the pipeline becoming a security risk?
The pipeline holds powerful credentials, so we scope them per environment, use short-lived federation instead of stored keys, restrict who can trigger applies, protect the webhook secret, and keep the server off the public internet where possible. Fork pull requests are not allowed to run plans.

Talk to an engineer about terraform ci/cd atlantis

Book a free 30-minute call. We review your current setup and tell you honestly whether and how we can help.

Written by Saddique Khan, DevOps / SRE / Cloud Consultant Engineer. Last updated 2026-10-08.