atlantis

Atlantis Terraform PR 自动化

补充说明

Atlantis 监听 Git 仓库的 Pull Request,在评论中执行 terraform plan/apply,把计划结果贴回 PR。适合需要评审和审计的 Terraform 工作流。

核心概念:webhook、repo config、atlantis.yaml、project、workflow 和 policy check。

常用示例

Docker 启动:

docker run -d --name atlantis \
  -p 4141:4141 \
  -v $(pwd)/atlantis-data:/atlantis-data \
  ghcr.io/runatlantis/atlantis:latest \
  server --atlantis-url=https://atlantis.example.com \
  --gh-user="$GH_USER" --gh-token="$GH_TOKEN" \
  --repo-allowlist='github.com/example/*'

仓库配置 atlantis.yaml:

version: 3
projects:
- name: prod
  dir: environments/prod
  workspace: default
  autoplan:
    when_modified: ["*.tf", "../modules/**/*.tf"]
    enabled: true

PR 评论:

atlantis plan
atlantis apply

易错点与排错