https://infracost.io logo
#general
Title
# general
m

melodic-ocean-16661

06/30/2023, 2:39 PM
we are getting like this output
b

busy-agent-35515

06/30/2023, 2:50 PM
Could you please point me to the example you're using? To receive the result as on the screenshot, the workflow needs to run a diff command against a baseline
Alternatively, you can add our GitHub app integration. It's faster and doesn't need actions: https://www.infracost.io/docs/integrations/github_app/
m

melodic-ocean-16661

06/30/2023, 3:57 PM
we used
image.png
c

crooked-daybreak-55253

06/30/2023, 4:05 PM
can you paste the contents of your GH action as text? That’s too small for me to read
m

melodic-ocean-16661

06/30/2023, 4:12 PM
jobs: infracost: runs-on: ubuntu-latest strategy: matrix: region: ${{fromJson(inputs.AWS_REGION)}} steps: - name: Checkout repository uses: actions/checkout@v2 - name: Set up Terraform uses: hashicorp/setup-terraform@v2 with: terraform_version: ${{ inputs.TERRAFORM_VERSION }} terraform_wrapper: false - name: Configure AWS credentials with OIDC uses: aws-actions/configure-aws-credentials@master with: role-to-assume: ${{ secrets.OIDC_CENTRAL_DEPLOY_ROLE }} aws-region: ${{ matrix.region }} # role-session-name: aws-terraform - name: Configuration Setup working-directory: ${{ inputs.WORKING_DIR }}/${{ matrix.region }} run: | sed -i '/bucket=/c\bucket="${{ inputs.STATE_BUCKET }}"' backend.tf sed -i '/key=/c\key="${{ inputs.STATE_FILE_PATH }}/${{ matrix.region }}/terraform.tfstate"' backend.tf sed -i '/role_arn=/c\role_arn="${{ inputs.OIDC_CENTRAL_DEPLOY_ROLE }}"' backend.tf sed -i '/role_arn=/c\role_arn="${{ inputs.ACCESS_ROLE }}"' provider.tf terraform init terraform validate - 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 }} # Generate Infracost JSON file as the baseline. --format=json - name: Generate Infracost cost estimate baseline run: | mkdir -p /tmp/${{ inputs.WORKING_DIR }} infracost breakdown --path=${{ inputs.WORKING_DIR }}/${{ matrix.region }} infracost breakdown --path=${{ inputs.WORKING_DIR }}/${{ matrix.region }} --format=json --out-file=/tmp/${{ inputs.WORKING_DIR }}/${{ matrix.region }}-base.json - name: Generate Infracost diff run: | infracost diff --path=${{ inputs.WORKING_DIR }}/${{ matrix.region }} --compare-to=/tmp/${{ inputs.WORKING_DIR }}/${{ matrix.region }}-base.json infracost diff --path=${{ inputs.WORKING_DIR }}/${{ matrix.region }} --compare-to=/tmp/${{ inputs.WORKING_DIR }}/${{ matrix.region }}-base.json --format=json --out-file=/tmp/${{ inputs.WORKING_DIR }}/${{ matrix.region }}-diff.json - name: Post Infracost comment if: github.event_name == 'pull_request' run: | infracost comment github --path=/tmp/${{ inputs.WORKING_DIR }}/${{ matrix.region }}-diff.json --repo=$GITHUB_REPOSITORY --github-token=${{ secrets.GIT_TOKEN }} --pull-request=${{github.event.pull_request.number}} --behavior=new
c

crooked-daybreak-55253

06/30/2023, 4:22 PM
Ok so if I understand, you’re seeing two problems: 1. There is no difference (previous = $99, new = $99, and diff = $0) 2. You see two comments with one project each, instead of one comment with two projects Anything else?
Ok for #1 (the diff problem) you are calling
infracost diff
with the same path that was used to create the baseline with
infracost breakdown
. There is no difference because they are the same code. If you look at this example you can see the flow is:
Copy code
...
- check out base branch
- run infracost breakdown to generate baseline
- check out pr branch
- run infracost diff to compare PR branch to baseline
For #2, I think the multiple comments are from a race condition with the matrix build. I think you may not need a matrix build at all if you follow the above example — this uses the built-in HCL parsing and you don’t need the calls to the terraform cli (i.e.
terraform init, etc…
. If you really do need a matrix build, you need to have the matrix step save the output of each
infracost diff
, then have another job that combines the outputs and creates a single comment with
infracost comment
. You can see an example that uses terraform plan files here,
m

melodic-ocean-16661

06/30/2023, 4:59 PM
ok thanks
I will look more and will update you
2 Views