Skip to main content

Atlantis

Run Infracost alongside Atlantis to see cloud cost estimates and FinOps best practices in pull requests.

tip

If you use Atlantis with GitHub, GitLab, or Azure Repos, we recommend the GitHub App, GitLab App, or Azure Repos App instead — they're simpler to set up and faster to run.

1. Decide a deployment option

Atlantis doesn't have a plugin system, so Infracost has to be made available inside the Atlantis container. Pick one of:

Use the infracost/infracost-atlantis Docker images, which extend the Atlantis image with the Infracost CLI baked in. We maintain tags for the latest two 0.x versions of Atlantis:

  • infracost/infracost-atlantis:atlantis0.42-infracost0.10 — latest patch of Atlantis 0.42 and Infracost 0.10
  • infracost/infracost-atlantis:atlantis0.41-infracost0.10 — latest patch of Atlantis 0.41 and Infracost 0.10
  • infracost/infracost-atlantis:latest — latest of both

b. Build your own Docker image

If you already use a custom Atlantis image, copy the top RUN command from the reference Dockerfile into your own.

c. Install via a pre-workflow hook (good for testing)

Use Atlantis pre_workflow_hooks to install the CLI on the running server. This lets you try Infracost without rebuilding your image — once you're happy, switch to one of the options above.

repos:
- id: /.*/
workflow: terraform-infracost
pre_workflow_hooks:
# Install Infracost, then call /tmp/infracost in your workflow steps
- run: |
/tmp/infracost --version && [ $(/tmp/infracost --version 2>&1 | grep -c "A new version of Infracost is available") = 0 ] || \
curl -L https://infracost.io/downloads/v0.10/infracost-linux-amd64.tar.gz --output infracost.tar.gz && \
tar -xvf infracost.tar.gz && \
mv infracost-linux-amd64 /tmp/infracost

When using this option, change Infracost CLI invocations to /tmp/infracost, and pass environment variables such as INFRACOST_API_KEY into the Atlantis container.

2. Set up Infracost

Once you've picked a deployment option, follow the Atlantis Infracost example to wire up the workflow.

3. Test the integration

Open a test PR — see these steps for what to expect.

Notes

Private Terraform modules

To use Terraform modules hosted in private git repos, add --write-git-creds to your atlantis server command.

Project names

Project names default to the relative path of the project via Atlantis's $REPO_REL_DIR. See Projects to customize them via a config file.

Terragrunt

If you use Atlantis with Terragrunt:

  1. Add terragrunt to your Docker image:

    FROM infracost/infracost-atlantis:latest

    RUN curl -L https://github.com/gruntwork-io/terragrunt/releases/download/v0.36.0/terragrunt_linux_amd64 --output terragrunt && \
    chmod +x terragrunt && \
    mv terragrunt /usr/local/bin
  2. Add a Terragrunt workflow to repos.yaml / atlantis.yaml:

    repos:
    - id: /.*/
    workflow: terragrunt-infracost
    workflows:
    terragrunt-infracost:
    plan:
    steps:
    - env:
    name: INFRACOST_OUTPUT
    command: 'echo "/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM/$WORKSPACE-${REPO_REL_DIR//\//-}-infracost.json"'
    - env:
    name: TERRAGRUNT_TFPATH
    command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
    - run: terragrunt plan -out=$PLANFILE
    - run: terragrunt show -json $PLANFILE > $SHOWFILE
    # Add the Infracost CLI steps here

Overriding metadata

If you use Infracost Cloud, you may need to override metadata such as the PR author or title shown on the dashboard:

INFRACOST_VCS_PROVIDER="github" # Use "github" for GitHub Enterprise too
INFRACOST_VCS_REPOSITORY_URL="https://github.com/$BASE_REPO_OWNER/$BASE_REPO_NAME"
INFRACOST_VCS_PULL_REQUEST_URL="$INFRACOST_VCS_REPOSITORY_URL/pulls/$PULL_NUM"
INFRACOST_VCS_PULL_REQUEST_AUTHOR="$PULL_AUTHOR"
INFRACOST_VCS_BASE_BRANCH="$BASE_BRANCH_NAME"

INFRACOST_VCS_PULL_REQUEST_TITLE=\"$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: $GITHUB_TOKEN" \
"https://api.github.com/repos/$BASE_REPO_OWNER/$BASE_REPO_NAME/pulls/$PULL_NUM" | jq -r '.title')\"