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_requirementsand custom workflows in a server-side repo config - Write an
atlantis.yamlthat defines multiple projects with autoplan rules - Drive plan and apply with
atlantis planandatlantis applyPR 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.
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.
export WEBHOOK_SECRET="$(openssl rand -hex 32)" kubectl create namespace atlantiskubectl -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-chartshelm repo update# atlantis-values.yamlgithub: 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 serverorgAllowlist: "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: 256Mihelm install atlantis runatlantis/atlantis \ -f atlantis-values.yaml \ --namespace atlantisSecurity
orgAllowlistis 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:
Payload URL: https://atlantis.razorpay-internal.com/eventsContent type: application/jsonSecret: the value of $WEBHOOK_SECRETEvents: Pull requests, Pull request reviews, Issue comments, PushesHow 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.
# Added to atlantis-values.yamlrepoConfig: | 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: - applyhelm upgrade atlantis runatlantis/atlantis -f atlantis-values.yaml --namespace atlantisRemember
tflintandconftestmust exist inside the Atlantis container. Build a small custom image on top of the official one that adds both binaries and your/policiesdirectory.
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.
# atlantis.yaml at the repo rootversion: 3projects: - 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 checkHow 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.
# Atlantis posts something like this on the PR:Ran Plan for project: prod-vpc dir: environments/prod/vpcPlan: 2 to add, 1 to change, 0 to destroy # Re-plan one project after pushing a fixatlantis plan -p prod-vpc # After approval, apply one projectatlantis apply -p prod-vpc # Or apply every planned project in the PRatlantis applyHow 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:
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.
# Example policy failure posted as a PR commentFAIL - tfplan.json - main - Security group sg-orders must not allow 0.0.0.0/0 on port 22TipA 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_requirementson the server. Withoutapprovedandmergeable, 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 MistakeSetting
apply_requirementsor a customworkflows:block only inatlantis.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 |