Skip to content

infracost/actions

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

221 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Infracost GitHub Actions

This repository contains GitHub Actions for running Infracost in your CI pipeline to see cloud cost estimates for Terraform in pull requests.

We recommend using the Infracost GitHub App where possible as it's simpler to set up and faster to run. If your organization doesn't allow GitHub App installations, use the actions below as an alternative.

Actions

Installs the Infracost CLI into your workflow. You then run infracost breakdown, infracost diff, and infracost comment as separate steps to generate cost estimates and post PR comments.

Full example

- name: Setup Infracost
  uses: infracost/actions/setup@v3
  with:
    api-key: ${{ secrets.INFRACOST_API_KEY }}

- name: Checkout base branch
  uses: actions/checkout@v4
  with:
    ref: '${{ github.event.pull_request.base.ref }}'

- name: Generate Infracost cost estimate baseline
  run: |
    infracost breakdown --path=. \
                        --format=json \
                        --out-file=/tmp/infracost-base.json

- name: Checkout PR branch
  uses: actions/checkout@v4

- name: Generate Infracost diff
  run: |
    infracost diff --path=. \
                    --format=json \
                    --compare-to=/tmp/infracost-base.json \
                    --out-file=/tmp/infracost.json

- name: Post Infracost comment
  run: |
    infracost comment github --path=/tmp/infracost.json \
                             --repo=$GITHUB_REPOSITORY \
                             --github-token=${{ github.token }} \
                             --pull-request=${{ github.event.pull_request.number }} \
                             --behavior=update

See the setup README for the full list of inputs.

diff and scan (early access)

We are developing a new generation of GitHub Actions that simplify setup and provide deeper integration with the Infracost dashboard. These actions are currently in early access and require enablement on your account. Please contact your sales representative to get access.

Early access actions

Computes cost differences between two branches, posts a PR comment, and manages PR status in the Infracost dashboard. Handles the full PR lifecycle β€” scans on open/sync/reopen, updates status on close.

Scans a single directory and uploads baseline cost data to the Infracost dashboard. Use this on pushes to your default branch to keep the dashboard up to date.

Example

on:
  pull_request:
    types: [opened, synchronize, closed, reopened]
  push:
    branches: [main]

permissions:
  contents: read
  pull-requests: write

jobs:
  diff:
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        if: github.event.action != 'closed'
        with:
          path: head

      - uses: actions/checkout@v4
        if: github.event.action != 'closed'
        with:
          ref: ${{ github.event.pull_request.base.ref }}
          path: base

      - uses: infracost/actions/diff@v4
        with:
          api-key: ${{ secrets.INFRACOST_API_KEY }}
          base-path: base
          head-path: head

  scan:
    if: github.event_name == 'push'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: infracost/actions/scan@v4
        with:
          api-key: ${{ secrets.INFRACOST_API_KEY }}
          path: .

See the diff README and scan README for the full list of inputs.

Contributing

We welcome contributions! Please start by opening a thread in GitHub Discussions to discuss your idea before submitting a PR.

Bugs and feedback

If you run into any issues or have feedback, please open a thread in GitHub Discussions. We'd love to hear from you!

License

Apache License 2.0

About

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

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors