infracost/actions

Trouble with infracost diff

crayon-robertelliott opened this issue · 2 comments

I'm likely doing something wrong but just not sure what. I can get an infracost breakdown to work in my workflow, however adding infracost diff is having problems. Any advice would be appreciated.
So the first part of the job in the workflow it runs terraform init,workspace,plan then I have the following:

    - name: Setup Infracost
      uses: infracost/actions/setup@v2.1.0
      with:
        api-key: ${{ secrets.INFRACOST_API_KEY }}
    
    # - name: Checkout base branch
    #   uses: actions/checkout@v3
    #   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@v3
      with:
        ref: '${{ github.event.pull_request.head.ref }}'

    - 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=${{ secrets.GITHUB_TOKEN }} \
                                 --pull-request=${{github.event.pull_request.number}} \
                                 --behavior=update \
                                 --policy-path=${{ github.workspace }}/.github/infracost/infracost-policy.rego

The comment looks like this :
image
So I'm not sure why Diff goes to to $0. I also have the checkout base branch commented out as if I do run it the infracost comment gives me $0's across the board with warnings in the logs like:
time="2023-04-19T14:56:02Z" level=warning msg="No products found for module.avd_vm_pooled_module.azurerm_windows_virtual_machine.main[0] Instance usage (hybrid benefit, Standard_D2s_v3), using 0.00"

Hi @crayon-robertelliott - sorry to hear about that. The Checkout base branch is definitely needed as the idea is that you first run infracost on the master branch to generate a baseline, then you checkout the PR branch and you generate a diff from that and the baseline. The using 0.00 is interesting as that means the CLI couldn't find the price of that resource.

  1. Can you please run infracost breakdown --path . --log-level debug on your laptop on the latest master branch and look for that line in the logs?
  2. Then add a code snippet of the Terraform resource that generated that log line so we can recreate the issue and fix it.

I'm hoping that'll fix the issue, but if you like we can also jump on a quick screenshare to debug it faster. Email me ali.hosseini@infracost.io if you'd like that.

Hi @alikhajeh1, thanks I'll reach out to you as the logs are really long.