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
repo-allowlist 太宽,任何仓库都能触发 apply。atlantis.yaml 的 dir 和 workspace 写错,计划空跑。apply_requirements,未经审批就能 apply。