Atlantis Cheat Sheet
Overview
Atlantis is an open-source Terraform/OpenTofu pull request automation server β GitOps for infrastructure code, running plan/apply directly from PR comments.
| |
| Strengths | Simple self-hosted setup Β· plan output directly in PRs Β· full audit trail in Git Β· supports Terraform, OpenTofu, Terragrunt Β· no SaaS dependency Β· integrates with GitHub/GitLab/Bitbucket |
| Weaknesses | No built-in UI or run history Β· no native RBAC beyond PR approval Β· single point of failure if unmanaged Β· stateless (no persistent dashboard) |
| Best for | Teams adopting GitOps for Terraform, PR-based IaC review workflows, open-source alternative to Terraform Cloud/Enterprise, small-to-medium platform teams |
Installation & Setup
# ββ Binary download βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# https://github.com/runatlantis/atlantis/releases
curl -Lo atlantis.zip \
"https://github.com/runatlantis/atlantis/releases/latest/download/atlantis_linux_amd64.zip"
unzip atlantis.zip && chmod +x atlantis && mv atlantis /usr/local/bin/
atlantis version
# ββ Docker run ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
docker run -d \
-p 4141:4141 \
--name atlantis \
-e ATLANTIS_GH_USER=my-bot-user \
-e ATLANTIS_GH_TOKEN=$GITHUB_TOKEN \
-e ATLANTIS_GH_WEBHOOK_SECRET=$WEBHOOK_SECRET \
-e ATLANTIS_REPO_ALLOWLIST="github.com/my-org/*" \
ghcr.io/runatlantis/atlantis server
# ββ Helm (Kubernetes) βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
helm repo add runatlantis https://runatlantis.github.io/helm-charts
helm repo update
helm install atlantis runatlantis/atlantis \
--namespace atlantis --create-namespace \
--set orgAllowlist="github.com/my-org/*" \
--set github.user=my-bot-user \
--set github.token=$GITHUB_TOKEN \
--set github.secret=$WEBHOOK_SECRET \
--set service.type=LoadBalancer
# Key environment variables
export ATLANTIS_GH_USER="my-bot-user" # GitHub bot username
export ATLANTIS_GH_TOKEN="ghp_..." # GitHub personal access token
export ATLANTIS_GH_WEBHOOK_SECRET="secret123" # Webhook secret (set in GitHub)
export ATLANTIS_REPO_ALLOWLIST="github.com/my-org/*" # allowed repos (glob)
export ATLANTIS_ATLANTIS_URL="https://atlantis.example.com" # public URL
# GitLab equivalent env vars
export ATLANTIS_GITLAB_HOSTNAME="gitlab.example.com"
export ATLANTIS_GITLAB_TOKEN="glpat-..."
export ATLANTIS_GITLAB_WEBHOOK_SECRET="secret123"
atlantis.yaml β Repo Config
# Place in the root of your Terraform repo
version: 3
# ββ Autoplanning ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
automerge: false # auto-merge PR after apply
parallel_plan: true # run plan for all projects in parallel
parallel_apply: false # apply sequentially (safer)
projects:
# ββ Simple project (single environment) ββββββββββββββββββββββββββββββββββ
- name: networking
dir: modules/networking # path relative to repo root
workspace: default
terraform_version: ~> 1.9.0 # enforced version
autoplan:
enabled: true
when_modified:
- "**/*.tf"
- "**/*.tfvars"
apply_requirements:
- approved # PR must be approved
- mergeable # PR must have no conflicts
# ββ Multi-workspace (one dir, multiple envs) ββββββββββββββββββββββββββββββ
- name: app-dev
dir: services/app
workspace: dev
autoplan:
enabled: true
when_modified: ["**/*.tf"]
- name: app-prod
dir: services/app
workspace: prod
apply_requirements:
- approved
- mergeable
- undiverged # branch must be up-to-date with base
# ββ Custom workflow βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
workflows:
custom:
plan:
steps:
- init
- run: tflint --chdir $PROJECT_DIR
- run: trivy config --exit-code 0 $PROJECT_DIR
- plan
apply:
steps:
- apply
PR Workflow
# Commands typed as PR comments on GitHub/GitLab/Bitbucket
atlantis plan # run terraform plan for all modified projects
atlantis plan -p networking # plan only the 'networking' project
atlantis plan -d modules/networking # plan by directory
atlantis apply # apply all planned projects
atlantis apply -p networking # apply only 'networking' project
atlantis unlock # unlock all plan locks for this PR
atlantis unlock -p networking # unlock a specific project
atlantis import -p networking \
aws_vpc.main vpc-abc1234 # import existing resource into state
atlantis state rm -p networking \
aws_vpc.main # remove resource from state
atlantis version # show Terraform version used
# ββ PR output ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Atlantis posts plan output as a PR comment with expandable diff
# After all projects planned: "Respond with atlantis apply to apply the plans"
# After all projects applied: "All projects applied successfully"
Server Config
# ββ Start server with flags βββββββββββββββββββββββββββββββββββββββββββββββββββ
atlantis server \
--repo-allowlist="github.com/my-org/*" \
--gh-user=my-bot-user \
--gh-token=$GITHUB_TOKEN \
--gh-webhook-secret=$WEBHOOK_SECRET \
--atlantis-url=https://atlantis.example.com \
--port=4141 \
--log-level=info \
--automerge \
--parallel-plan \
--tf-download-url=https://releases.hashicorp.com/terraform
# ββ Server YAML config (alternative to flags) βββββββββββββββββββββββββββββββββ
# atlantis.yaml at server level or via --config flag
# repos:
# - id: github.com/my-org/my-repo
# apply_requirements: [approved]
# allowed_overrides: [apply_requirements, workflow]
# ββ Repos config file βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# repos.yaml (passed via --repo-config)
repos:
- id: /.*/
apply_requirements: []
allowed_overrides: [apply_requirements, workflow]
allow_custom_workflows: true
# ββ OpenTofu support ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
atlantis server \
--default-tf-version=tofu1.8.0 \
--tf-download-url=https://github.com/opentofu/opentofu/releases/download
# ββ Useful flags ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
--var-file-allowlist="*.tfvars" # allow -var-file in plan commands
--write-git-creds # write .git-credentials for private modules
--hide-prev-plan-comments # minimise old plan comments
--silence-no-projects # no comment if no projects found
--disable-apply-all # disallow `atlantis apply` without -p flag
Custom Workflows
# In atlantis.yaml β extend plan/apply with extra steps
workflows:
security-checked:
plan:
steps:
- init:
extra_args: ["-upgrade"]
- run: tflint --chdir $PROJECT_DIR --format compact
- run: |
tfsec $PROJECT_DIR --soft-fail \
--format=text --minimum-severity=HIGH
- run: |
conftest test $PROJECT_DIR \
--policy ./policies/ --all-namespaces
- plan:
extra_args: ["-parallelism=20"]
apply:
steps:
- run: echo "Applying $PROJECT_NAME in $WORKSPACE"
- apply
# Available environment variables in run steps:
# $PROJECT_NAME name from atlantis.yaml
# $PROJECT_DIR absolute path to project dir
# $WORKSPACE Terraform workspace
# $PLANFILE path to the .tfplan file (apply only)
# $REPODIR repo root directory
# $HEAD_COMMIT git SHA of the PR head
# $BASE_REPO_OWNER GitHub org/user
# $BASE_REPO_NAME repo name
# $PULL_NUM PR number
Multi-Workspace & Multi-Project
# ββ Terragrunt support ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
workflows:
terragrunt:
plan:
steps:
- run: terragrunt plan -out $PLANFILE
apply:
steps:
- run: terragrunt apply $PLANFILE
# ββ Multiple workspaces per directory βββββββββββββββββββββββββββββββββββββββββ
projects:
- name: vpc-dev
dir: infra/vpc
workspace: dev
- name: vpc-staging
dir: infra/vpc
workspace: staging
- name: vpc-prod
dir: infra/vpc
workspace: prod
apply_requirements: [approved, mergeable]
# ββ Dynamic project detection (no atlantis.yaml in repo) βββββββββββββββββββββ
# Server flag: --autoplan-modules
# Atlantis will detect changed directories automatically
atlantis server --autoplan-modules
# ββ Per-project variable files ββββββββββββββββββββββββββββββββββββββββββββββββ
# Comment in PR:
# atlantis plan -p vpc-prod -- -var-file=vars/prod.tfvars
Access Control
# ββ apply_requirements per project βββββββββββββββββββββββββββββββββββββββββββ
apply_requirements:
- approved # at least 1 approving review
- mergeable # no unresolved conflicts, required checks passed
- undiverged # branch is up-to-date with base branch
# ββ per-repo override (repos.yaml) βββββββββββββββββββββββββββββββββββββββββββ
repos:
- id: github.com/my-org/critical-infra
apply_requirements: [approved, mergeable, undiverged]
allowed_overrides: [] # repo cannot override anything
allow_custom_workflows: false
- id: github.com/my-org/sandbox-.* # regex matching
apply_requirements: []
allow_custom_workflows: true
# ββ JSON inline config (no file needed) ββββββββββββββββββββββββββββββββββββββ
atlantis server \
--repo-config-json='{"repos":[{"id":"/.*/","allow_custom_workflows":true}]}'
Debugging
# ββ Increase log verbosity ββββββββββββββββββββββββββββββββββββββββββββββββββββ
atlantis server --log-level=debug
# ββ Check webhook delivery (GitHub UI) βββββββββββββββββββββββββββββββββββββββ
# Settings β Webhooks β select webhook β Recent Deliveries
# ββ Atlantis health & locks βββββββββββββββββββββββββββββββββββββββββββββββββββ
curl http://localhost:4141/healthz
curl http://localhost:4141/status
# List & delete locks via API
curl http://localhost:4141/atlantis/locks # list all locks
curl -X DELETE \
"http://localhost:4141/atlantis/locks?id=my-org/repo/dir/default"
# ββ Common issues βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# "command not allowed" β project not in repo-allowlist
# "approval required" β check apply_requirements
# "workspace is locked" β previous plan not applied; atlantis unlock to reset
# "module not found" β set --write-git-creds or configure SSH key for private modules
# Webhook 400 errors β wrong HMAC secret or payload content-type mismatch
# ββ Test webhook locally (ngrok) βββββββββββββββββββββββββββββββββββββββββββββ
atlantis server --repo-allowlist="github.com/my-org/*" \
--atlantis-url=$(ngrok http 4141 --log=stdout | grep "Forwarding" | head -1 | awk '{print $2}')
Further Resources