Thanks to visit codestin.com
Credit goes to github.com

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

224 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

A streamlined alternative to chaining setup plus individual CLI steps. These actions integrate directly with the Infracost dashboard and handle the full PR lifecycle β€” scanning on open/sync/reopen, updating status on close.

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, and marks the PR as merged or closed in the dashboard when it ends.

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:
      # Checkout steps are skipped on closed PRs since diffing is not needed β€”
      # the diff action below detects the closed event and updates the PR's
      # status in the Infracost dashboard (MERGED or CLOSED) without scanning.
      - 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.

setup (legacy)

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. New integrations should prefer diff and scan above.

Legacy setup action

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.

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