Skip to main content

Automating Terraform with Atlantis Pull Requests

Set up Atlantis to run Terraform plan and apply from GitHub pull requests, with locking, approvals, and policy checks for safer team workflows.

26 Terms

Overview and What You Will Learn

Atlantis is a self-hosted, open-source server that runs terraform plan and terraform apply in response to GitHub pull request events and comments, then posts the results back on the pull request. Reviewers read the plan in the PR, approve the code, and type atlantis apply to make the change, so nobody runs Terraform from a personal laptop.

This lab stands up a real Atlantis server, connects it to GitHub, enforces approvals on the server side, and shows where Atlantis fits next to GitHub Actions and HCP Terraform (formerly Terraform Cloud).

By the end of this lab you will be able to:

  • Install Atlantis on Kubernetes with the official Helm chart and a Kubernetes Secret for credentials
  • Configure the GitHub webhook that delivers pull request events to Atlantis
  • Enforce apply_requirements and custom workflows in a server-side repo config
  • Write an atlantis.yaml that defines multiple projects with autoplan rules
  • Drive plan and apply with atlantis plan and atlantis apply PR comments
  • Add a policy-check step to the plan workflow
  • Choose between Atlantis, GitHub Actions, and HCP Terraform for your team

Why This Matters in Production

Picture a platform team like the one at Razorpay or Stripe, where dozens of engineers change payment infrastructure every week. When plan output lives in a separate CI tab, reviewers tend to skim a green checkmark and approve. Atlantis puts the full plan, the lock status, and the apply trigger inside the pull request itself, which makes reading the plan part of the normal review. It also gives you one audited place where apply runs, with one set of cloud credentials. (This scenario is illustrative, not a documented incident.)

Core Principles

Atlantis is a long-running server. GitHub sends it a webhook when a pull request opens or a comment is posted, Atlantis clones the branch, runs Terraform in a working directory per project, and replies with a comment.

sequenceDiagram participant E as Engineer participant G as GitHub participant A as Atlantis participant C as AWS E->>G: Open PR G->>A: Send webhook A->>C: Run plan A->>G: Post plan E->>G: Comment apply G->>A: Send webhook A->>C: Run apply A->>G: Post result

While a plan for a project directory is unapplied, Atlantis holds a lock on that directory, so a second pull request touching the same directory cannot plan until the first is applied or discarded. This is what prevents two engineers from changing the same state at once.

Detailed Step-by-Step Practical Lab

How to Install Atlantis on Kubernetes with Helm

The Helm chart reads the GitHub token and webhook secret from an existing Kubernetes Secret, so no credential ever appears in a values file.

Bash
export WEBHOOK_SECRET="$(openssl rand -hex 32)"
kubectl create namespace atlantis
kubectl -n atlantis create secret generic atlantis-vcs \
--from-literal=token="$GITHUB_TOKEN" \
--from-literal=secret="$WEBHOOK_SECRET"
helm repo add runatlantis https://runatlantis.github.io/helm-charts
helm repo update
YAML
# atlantis-values.yaml
github:
user: razorpay-infra-bot # GitHub user that owns the token
vcsSecretName: atlantis-vcs # Secret with keys: token, secret
# Only repos matching this pattern may use this server
orgAllowlist: "github.com/razorpay-platform/*"
serviceAccount:
annotations:
# IRSA role: the AWS identity Atlantis uses when it runs Terraform
eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/atlantis-terraform
resources:
requests:
cpu: 250m
memory: 256Mi
Bash
helm install atlantis runatlantis/atlantis \
-f atlantis-values.yaml \
--namespace atlantis
Security

orgAllowlist is not optional in practice. Without it, your server will process webhooks for any repository that can reach its URL, and run Terraform from that repository with your server's cloud credentials.

How to Configure the GitHub Webhook for Atlantis

Atlantis only acts on events it receives, so the webhook must be delivered and signed with the same secret stored in the Kubernetes Secret.

In the repository, open Settings, then Webhooks, then Add webhook:

TEXT
Payload URL: https://atlantis.razorpay-internal.com/events
Content type: application/json
Secret: the value of $WEBHOOK_SECRET
Events: Pull requests, Pull request reviews, Issue comments, Pushes
How to Enforce Approvals with a Server-Side Repo Config

Approval rules belong in the server-side repo config, not in the repository. By default a repo-level atlantis.yaml cannot override apply_requirements or define custom workflows unless the server allows it, so set the rules where engineers cannot edit them in a PR.

YAML
# Added to atlantis-values.yaml
repoConfig: |
repos:
- id: github.com/razorpay-platform/infrastructure
apply_requirements: [approved, mergeable] # both must be true before apply
allowed_overrides: [workflow] # projects may pick a named workflow
allow_custom_workflows: false # but cannot define new ones in the PR
workflows:
default:
plan:
steps:
- init
- run: tflint
- plan
- show # writes plan JSON to $SHOWFILE
- run: conftest test $SHOWFILE --policy /policies
apply:
steps:
- apply
staging:
plan:
steps:
- init
- plan
apply:
steps:
- apply
Bash
helm upgrade atlantis runatlantis/atlantis -f atlantis-values.yaml --namespace atlantis
Remember

tflint and conftest must exist inside the Atlantis container. Build a small custom image on top of the official one that adds both binaries and your /policies directory.

How to Define Projects in atlantis.yaml

A project maps a directory to a workflow, and autoplan tells Atlantis which file changes should trigger it.

YAML
# atlantis.yaml at the repo root
version: 3
projects:
- name: prod-vpc
dir: environments/prod/vpc
workflow: default
autoplan:
when_modified: ["*.tf", "../../modules/**/*.tf"]
- name: prod-ecs-orders
dir: environments/prod/ecs-service-orders
workflow: default
- name: staging-vpc
dir: environments/staging/vpc
workflow: staging # lighter workflow without the policy check
How to Run Plan and Apply from Pull Request Comments

When a PR changes files in a project, Atlantis plans that project automatically and comments with the result. Everything after that is a PR comment.

Bash
# Atlantis posts something like this on the PR:
Ran Plan for project: prod-vpc dir: environments/prod/vpc
Plan: 2 to add, 1 to change, 0 to destroy
# Re-plan one project after pushing a fix
atlantis plan -p prod-vpc
# After approval, apply one project
atlantis apply -p prod-vpc
# Or apply every planned project in the PR
atlantis apply
How Atlantis Locking Prevents Concurrent Applies

If PR #142 has an unapplied plan for environments/prod/vpc and PR #145 also changes that directory, Atlantis refuses to plan on #145 and replies with a message similar to this:

TEXT
This project is currently locked by an unapplied plan from pull request #142.
Apply that plan and merge, or discard it, before planning here.

No engineer has to coordinate by hand. To release a lock from an abandoned PR, comment atlantis unlock on that PR or delete the lock in the Atlantis UI.

How to Add a Policy Check to the Plan Workflow

The show step converts the binary plan into JSON at $SHOWFILE, and conftest evaluates that JSON against your OPA policies. The binary $PLANFILE is not readable by conftest, which is a common mistake.

Bash
# Example policy failure posted as a PR comment
FAIL - tfplan.json - main - Security group sg-orders must not allow 0.0.0.0/0 on port 22
Tip

A policy that fails inside the plan workflow is posted before a human reviews. Reviewers then spend their time on intent rather than re-checking rules a machine already verified.

Atlantis vs GitHub Actions vs HCP Terraform

Atlantis suits teams that want a comment-driven approval loop with built-in locking and are happy to run a server. GitHub Actions suits teams that want no extra server, and HCP Terraform suits teams that want managed state, runs, and policy.

Atlantis GitHub Actions
Where review happens PR comments only PR comment plus Actions tab
Hosting You run the server Managed by GitHub
Locking Built in, per project directory You build it yourself
Setup effort Higher: server, webhook, image Lower: workflow YAML
Atlantis HCP Terraform
Hosting Self-hosted, open source Managed SaaS
State storage Your own backend, such as S3 Built-in remote state
Policy as code OPA through workflow steps Sentinel and OPA, built in
Cost No license, you pay in operations Usage-based, check current plans

Production Best Practices & Common Pitfalls

  • Set apply_requirements on the server. Without approved and mergeable, anyone able to comment can trigger an apply. Putting the rule in the server-side repo config means a PR cannot weaken it.
  • Scope the server's AWS role tightly. Atlantis can do whatever its cloud identity can do, so an admin role gives every watched repository admin blast radius. Use IRSA, and consider one Atlantis instance per environment.
  • Never skip orgAllowlist. An open webhook with no allowlist is the most common Atlantis misconfiguration.
  • Keep the webhook secret and token in a Kubernetes Secret. Do not put them in values files or Git.
  • Use different workflows for staging and production. Production gets policy checks and approvals, staging stays fast.
  • Pin Atlantis, Terraform, and tool versions in your image. An unpinned image can change plan behavior between two PRs.
Common Mistake

Setting apply_requirements or a custom workflows: block only in atlantis.yaml. Unless the server allows overrides, Atlantis rejects the repo config with an error, and teams then loosen the server rules instead of fixing the placement.

Quick Reference & Troubleshooting Commands

Command (PR comment) Description
atlantis plan Plan every changed project in the PR
atlantis plan -p <project> Plan one named project
atlantis apply Apply every planned, approved project
atlantis apply -p <project> Apply one named project
atlantis unlock Discard plans and release locks held by this PR
Error Root Cause Fix
No response on a new PR Webhook not delivered or signature mismatch Check GitHub's webhook Recent Deliveries for the response code
Project is currently locked Another open PR holds the plan lock Apply or close that PR, or comment atlantis unlock there
Apply requirements not met Missing approval or merge conflict Get an approval and resolve conflicts, then re-run apply
Repo config rejected for overrides Repo atlantis.yaml sets a field the server does not allow Move the setting to server-side repoConfig or add it to allowed_overrides
conftest cannot parse plan Policy ran against $PLANFILE instead of $SHOWFILE Add the show step and use $SHOWFILE

Resources

Explore More in Terraform in Production - CI/CD, Secrets, and Governance

All 3 Topics

Frequently Asked Questions

Is Automating Terraform with Atlantis Pull Requests free to learn on DevOps Network?

Yes - this topic, like everything on DevOps Network, is 100% free with no paywall or sign-up gate.

What does the Automating Terraform with Atlantis Pull Requests topic cover?

Set up Atlantis to run Terraform plan and apply from GitHub pull requests, with locking, approvals, and policy checks for safer team workflows.

Found a mistake, an outdated step or a broken link?