• Stars
    star
    129
  • Rank 279,262 (Top 6 %)
  • Language
    Dockerfile
  • License
    Apache License 2.0
  • Created almost 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Atlantis integration for Infracost. Shows cloud cost estimates for Terraform in pull requests.

Infracost Atlantis Integration

This repo shows how Infracost can be used with Atlantis, so you can see cloud cost estimates for Terraform in pull requests πŸ’°

Example screenshot

Usage

1. Decide deployment option

Since Atlantis does not have a plugins concept, you need to decide which deployment option to use:

a. Use our Docker images (recommended)

Use our infracost-atlantis Docker images that extend the Atlantis image to add Infracost. We maintain tags for the latest two 0.x versions of Atlantis:

  • infracost/infracost-atlantis:atlantis0.24-infracost0.10 latest patch version of Atlantis v0.24 and Infracost v0.10
  • infracost/infracost-atlantis:atlantis0.23-infracost0.10 latest patch version of Atlantis v0.23 and Infracost v0.10
  • infracost/infracost-atlantis:latest latest versions of Atlantis and Infracost

b. Build your own Docker image

If you already use a custom Docker image for Atlantis, copy the top RUN command from this Dockerfile into your Dockerfile.

c. Install in pre-workflow (good for testing)

Use Atlantis pre_workflow_hooks to dynamically install the Infracost CLI on a running Atlantis server (shown in the following repos.yml example). This enables you to test Infracost without changing your Docker image by installing it on each workflow run. Once you're happy with the results, you can use one of the above methods.

To use this method, add the following pre_workflow_hook to your chosen option in the next step. Also change references to the Infracost CLI invocation to /tmp/infracost in the the next step. Environment variables such as INFRACOST_API_KEY also need to be passed into the Atlantis container.

repos:
  - id: /.*/
    workflow: terraform-infracost
    pre_workflow_hooks:
      # Install Infracost, use `/tmp/infracost` to run the CLI in step 2
      - 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

2. Setup Infracost

Once you've decided, follow this guide to setup Infracost with Atlantis.

Additional examples

The following examples might be helpful to use alongside the above examples:

  • Slack: post cost estimates to Slack
  • Conftest: check cost policies using Atlantis' native Conftest integration and Infracost cost estimates.

If you do not use Conftest/Open Policy Agent, you can still set thresholds using bash and jq so notifications or pull request comments are only sent when cost thresholds are exceeded.

Atlantis usage notes

Private Terraform modules

To use with Terraform modules that are hosted in a private git repository you can add the --write-git-creds flag to your atlantis server command.

Terraform Cloud/Enterprise

To use with Terraform Cloud/Enterprise you can add the following flags to your atlantis server command: --tfe-hostname='MY_TFE_HOSTNAME' --tfe-token='MY_TFE_TOKEN'.

Project names

Project names default to the relative path of the project using the Atlantis $REPO_REL_DIR environment variable. See our docs to customize this.

Terragrunt

If you use Atlantis with Terragrunt, you should:

  1. Update your Docker image to include terragrunt, for example:

    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 the following YAML spec to repos.yaml or atlantis.yaml config files, altering it to fit your terragrunt project:

    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 custom steps here from the examples mentioned elsewhere in this readme

Overriding metadata

If you use Infracost Cloud, you might need to override metadata such as the pull request author or title that is shown on the Infracost Cloud dashboard.

INFRACOST_VCS_PROVIDER="github" # For GitHub Enterprise, also use "github"
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')\"

Contributing

Issues and pull requests are welcome! For development details, see the contributing guide. For major changes, including interface changes, please open an issue first to discuss what you would like to change. Join our community Slack channel, we are a friendly bunch and happy to help you get started :)

License

Apache License 2.0

More Repositories

1

infracost

Cloud cost estimates for Terraform in pull requestsπŸ’°πŸ“‰ Shift FinOps Left!
Go
10,979
star
2

vscode-infracost

See cost estimates for Terraform right in your editorπŸ’°πŸ“‰
TypeScript
1,792
star
3

cloud-pricing-api

GraphQL API for cloud pricing. Contains over 3M public prices from AWS, Azure and GCP. Self-updates prices via an automated weekly job.
TypeScript
348
star
4

actions

GitHub Action for Infracost. See cloud cost estimates for Terraform in pull requests. πŸ’°πŸ“‰ Love your cloud bill!
JavaScript
224
star
5

infracost-gh-action

GitHub Action for Infracost. Shows cloud cost estimates for Terraform in pull requests.
120
star
6

infracost-azure-devops

Azure DevOps integration for Infracost. Shows cloud cost estimates for Terraform in pull requests for Azure DevOps repos and GitHub repos.
TypeScript
30
star
7

helm-charts

Official Infracost Helm charts
Smarty
29
star
8

compost

Post pull request comments from multiple CI platforms
TypeScript
29
star
9

terraform-provider-infracost

This repo is deprecated, please use the https://infracost.io/usage-file/ instead.
Go
20
star
10

infracost-jenkins

Jenkins integration for Infracost. Shows cloud cost estimates for Terraform.
19
star
11

docs

Infracost docs
JavaScript
12
star
12

infracost-orb

CircleCI Orb for Infracost. Shows cloud cost estimates for Terraform in GitHub and BitBucket pull requests.
11
star
13

gh-actions-demo

Demo repo for Infracost GitHub Action
HCL
10
star
14

docusaurus-plugin-plausible

Docusaurus plugin for Plausible analytics
JavaScript
9
star
15

infracost-circleci

Atlantis integration for Bitbucket. Shows cloud cost estimates for Terraform in pull requests.
8
star
16

example-terraform

Example Terraform project
HCL
6
star
17

jetbrains-infracost

See cost estimates for Terraform right in your editorπŸ’°πŸ“‰
Kotlin
5
star
18

setup-infracost

Use https://github.com/infracost/actions
TypeScript
4
star
19

compost-action

Post pull request comments from multiple CI platforms
TypeScript
4
star
20

atlantis-demo

Demo repo for Infracost Atlantis integration
HCL
4
star
21

circleci-github-demo

Demo repo for Infracost running in CircleCI with GitHub
HCL
3
star
22

compost-go

Post pull request comments to multiple VCSs
Go
3
star
23

compost-e2e-tests-template

Testing repo for Compost E2E tests
2
star
24

infracost-gitlab-ci

GitLab CI examples for Infracost. Shows cloud cost estimates for Terraform in GitLab merge requests
2
star
25

cross-account-link

A Terraform module to set up an AWS cross-account link for Infracost Cloud.
HCL
1
star
26

jenkins-demo

Demo repo for Infracost running in Jenkins
HCL
1
star
27

compost-e2e-tests

Compost E2E test repo
1
star
28

azure-devops-github-demo

Demo repo for Infracost Azure DevOps integration
HCL
1
star
29

demo-repo

Demo repo for Infracost Cloud
HCL
1
star