Skip to content

Instantly share code, notes, and snippets.

@kasunsjc
Created December 10, 2022 20:39
Show Gist options
  • Select an option

  • Save kasunsjc/7bc067e35d2446d69c7f9033dbfcaa74 to your computer and use it in GitHub Desktop.

Select an option

Save kasunsjc/7bc067e35d2446d69c7f9033dbfcaa74 to your computer and use it in GitHub Desktop.
on: [pull_request]
env:
jobs:
infracost:
name: Infracost
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
env:
TF_ROOT: example-terraform/azure
steps:
- name: Setup Infracost
uses: infracost/actions/setup@v2
with:
api-key: ${{ secrets.INFRACOST_API_KEY }}
- name: Checkout base branch
uses: actions/checkout@v3
with:
ref: '${{ github.event.pull_request.base.ref }}'
# Generate Infracost JSON file as the baseline.
- name: Generate Infracost cost estimate baseline
run: |
infracost breakdown --path=${TF_ROOT} \
--format=json \
--out-file=/tmp/infracost-base.json
# Checkout the current PR branch so we can create a diff.
- name: Checkout PR branch
uses: actions/checkout@v3
# Generate an Infracost diff and save it to a JSON file.
- name: Generate Infracost diff
run: |
infracost diff --path=${TF_ROOT} \
--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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment