infracost/actions

Error: No INFRACOST_API_KEY environment variable is set.

heathsnow opened this issue · 10 comments

Description

I've started getting this error when running the action:

Error: No INFRACOST_API_KEY environment variable is set.

My workflows worked fine last time they ran so I'm wondering if something has changed with v2 since then.

From my understanding I only need the setup action to reference the API secret, like so:

    steps:
      - name: 'Setup Infracost'
        uses: infracost/actions/setup@v2
        with:
          api-key: ${{ secrets.INFRACOST_API_KEY }}

However, once I get to follow-up steps to either breakdown or diff I get the error.

Any idea what's going on?

Thanks in advance.

tim775 commented

Hi, there haven't been any changes to the action, but we did just release a new CLI version that would have been picked up by a new run.

When did the error happen and when was that last time it ran succesfully?

It also might not be a bad idea to "try again" since github had a pretty serious outage earlier today.

Rerunning produces the same error. It ran successfully 2 weeks ago with Setup Infracost CLI version 0.10.20. It first failed 1 week ago after a Dependabot run with Setup Infracost CLI version 0.10.21

Yep, I'm able to get it passing again if I use this:

    steps:
      - name: 'Setup Infracost'
        uses: infracost/actions/setup@v2
        with:
          api-key: ${{ secrets.INFRACOST_API_KEY }}
          version: 0.10.20

So something is wrong with the latest 0.10.21 version.

Hey, looks like it's working again with verion 0.10.22 which just released.

Thanks for the quick turnaround!

I spoke too soon. While some checks are passing others are still failing at the breakdown step.

version: 0.10.22

excerpt:

Run infracost breakdown --path=. \
  infracost breakdown --path=. \
                      --include-all-paths \
                      --format=json \
                      --out-file=/tmp/infracost-base.json
  shell: /usr/bin/bash -e {0}
  env:
    INFRACOST_GITHUB_ACTION: true
    INFRACOST_SKIP_UPDATE_CHECK: true
    INFRACOST_VCS_REPOSITORY_URL: <redacted>
    INFRACOST_VCS_PULL_REQUEST_URL: <redacted>
    INFRACOST_LOG_LEVEL: info
Error: No INFRACOST_API_KEY environment variable is set.
We run a free Cloud Pricing API, to get an API key run infracost auth login
Error: Process completed with exit code 1.

Okay, to add more mystery I'm seeing the same behavior with version 0.10.20 now as well. I just merged a PR that passed w/o error using version 0.10.20. The next PR in the same repo though is now failing with the Error: No INFRACOST_API_KEY environment variable is set. error while using the same 0.10.20 version. Hmmmm.

tim775 commented

That is really strange that it happens intermittenly. Do have any .env or .env.local files set? And maybe send a gist of your full GH Actions yaml so I can see if I notice anything.

If you want, hit me up on our slack channel: https://infracost.io/community-chat

Here's my basic infracost.yml I'm using (some pass config-file, some don't). Here's a behavior I'm seeing right now after some more testing. I have a Dependabot PR open that is currently failing it's infracost check with the error above. However, if I open another PR (w/o changing the infracost.yml at all) it passes.

Do you think it's possible that the failing PR is still using some old libraries that were cached or something? Maybe GitHub actions is reusing some cache even though it's reporting Setup Infracost CLI version 0.10.22.

I'm able to work around this issue by closing the currently failing PRs and opening new ones so that's good.

Well, I tested this theory by creating a PR while setting the Infracost version to 0.10.21 which I expected to fail. However, it's passing fine now. I don't know why I have Dependabot PRs failing. Typically, if it were a permission issue that would be resolved by my user rerunning the failing workflow.

I think I'll just close this issue for now and see if it's still an issue next month when I get Dependabot PRs again.

Thanks.

tim775 commented

Apparently Dependabot PRs don't have access to the regular github action secrets. There is a separate Dependabot section under Secrets and Variables in the report settings, so it seems like you should be able to set INFRACOST_API_KEY there as well.

This was a nice write up explaining it: https://danielabaron.me/blog/dependabot-secrets/