broad-zoo-34077
02/22/2024, 3:02 PMlittle-author-61621
billowy-electrician-57321
02/22/2024, 3:22 PMbillowy-electrician-57321
02/22/2024, 3:24 PMon:
workflow_call:
inputs:
environment:
required: true
type: string
project-directory:
required: true
type: string
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
pull-requests: write # Required to post comments
jobs:
infracost:
name: Infracost
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
env:
PROJECT_NAME : "${{ inputs.project-directory}}/${{ inputs.environment}}"
steps:
- name: Setup Infracost
uses: infracost/actions/setup@v2
# See <https://github.com/infracost/actions/tree/master/setup> for other inputs
# If you can't use this action, see Docker images in <https://infracost.io/cicd>
with:
api-key: ${{ secrets.INFRACOST_API_KEY }}
- name: Checkout base branch
uses: actions/checkout@v4
with:
ref: '${{ github.event.pull_request.base.ref }}'
# Checkout the base branch of the pull request (e.g. main/master).
- 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=${{ inputs.project-directory}} \
--project-name="${{ env.PROJECT_NAME }}" \
--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@v4
- name: Generate Infracost Diff Report
run: |
infracost diff --path=${{ inputs.project-directory}} \
--terraform-var-file envs/${{ inputs.environment}}/${{ vars.AWS_REGION }}/terraform.tfvars \
--project-name="${{ env.PROJECT_NAME }}" \
--format=json \
--compare-to=/tmp/infracost-base.json \
--out-file=/tmp/infracost-PR-diff.json
- name: Generate Infracost Breakdown Report
run: |
infracost breakdown --path=${{ inputs.project-directory}} \
--terraform-var-file envs/${{ inputs.environment}}/${{ vars.AWS_REGION }}/terraform.tfvars \
--project-name="${{ env.PROJECT_NAME }}" \
--show-skipped \
--format=html \
--out-file=/tmp/infracost-breakdown.html
# Posts a comment to the PR using the 'update' behavior.
# This creates a single comment and updates it. The "quietest" option.
# The other valid behaviors are:
# delete-and-new - Delete previous comments and create a new one.
# hide-and-new - Minimize previous comments and create a new one.
# new - Create a new cost estimate comment on every push.
# See <https://www.infracost.io/docs/features/cli_commands/#comment-on-pull-requests> for other options.
- name: Post Infracost comment
run: |
infracost comment github --path="/tmp/infracost-PR-diff.json" \
--repo=$GITHUB_REPOSITORY \
--github-token=${{github.token}} \
--pull-request=${{github.event.pull_request.number}} \
--behavior=update \
--tag="${{ env.PROJECT_NAME }}" \
--show-all-projects
- name: Upload Infracost Breakdown Report as Artifact
uses: actions/upload-artifact@v4
with:
name: Infracost Breakdown Report (${{ inputs.project-directory}}, ${{ inputs.environment }})
path: /tmp/infracost-breakdown.html
little-author-61621
--terraform-var-file
to the first breakdown command?billowy-electrician-57321
02/22/2024, 3:40 PMlittle-author-61621
billowy-electrician-57321
02/22/2024, 3:42 PMlittle-author-61621
billowy-electrician-57321
02/22/2024, 4:27 PMlittle-author-61621
infracost-PR-diff.json
must be missing a past breakdown for a project. Are you able to DM me that file and the infracost-baseline.json
file that’s causing this?billowy-electrician-57321
02/23/2024, 8:10 AMbillowy-electrician-57321
02/23/2024, 12:26 PMlittle-author-61621