https://infracost.io logo
#help
Title
# help
d

dazzling-airplane-3803

03/19/2024, 9:34 AM
Hey, you probably get that question often, when I try to run my bitbucket pipline with env and api key set, I still get api key error: Completed installing Infracost v0.10.34 [infracost_diff] infracost diff --path plan.json Error: INFRACOST_API_KEY is not set but is required, check your environment variable is named correctly or add your API key to your /root/.config/infracost/credentials.yml credentials file. What am I doing wrong? It doesnt seem like, that the project I am working on has /root/.. configured.
w

white-airport-8778

03/19/2024, 9:36 AM
Hey! Have you set the INFRACOST_API_KEY env var in your bitbucket pipeline? That’s step 4 in https://bitbucket.org/infracost/infracost-bitbucket-pipeline/src/master/ and you can get your API key from https://dashboard.infracost.io or running
infracost configure get api_key
if you already have the CLI running on your dev machine.
d

dazzling-airplane-3803

03/19/2024, 9:59 AM
Hey, yes I did, but I get the exact same error.
Also checked again, spelling is correct.
l

little-author-61621

03/19/2024, 10:20 AM
@dazzling-airplane-3803 this seems odd. Are you able to add the following curl to your pipeline so we can debug further?
Copy code
curl -i -H "User-Agent: infracost-debug-0fe936ed" -H "Content-Type: application/json" -H "X-Api-Key: $INFRACOST_API_KEY" <https://pricing.api.infracost.io/graphql>
@dazzling-airplane-3803 any luck with this yet?
d

dazzling-airplane-3803

03/21/2024, 7:49 AM
Hey @little-author-61621, sorry for the late reply. Thank you for your help, tbh idk, since our pipeline now complains about different stuff. I'll keep you updated, and anyhow, thank you for helping me out here!
l

little-author-61621

03/21/2024, 9:01 AM
Okay thank you @dazzling-airplane-3803!
d

dazzling-airplane-3803

03/22/2024, 6:51 AM
Hey @little-author-61621, still persists. So this is what I am running in my bitbucket pipeline:
Copy code
...
install_infracost:
  status:
    - test -x /usr/local/bin/infracost
  generates:
    - /usr/local/bin/infracost
  cmds:
     - curl -fsSL <https://raw.githubusercontent.com/infracost/infracost/master/scripts/install.sh%7C> sh

infracost_diff:
  dir: environments/{{.ENV}}/
  deps: [install_infracost]
  cmds:
    - infracost diff --path plan.json
And I added the infracost as an env variable in the bitbucket backend, still no luck, error: task: [infracost_diff] infracost diff --path plan.json [91mError:[0m [96mINFRACOST_API_KEY[0m is not set but is required, check your environment variable is named correctly or add your API key to your [96m/root/.config/infracost/credentials.yml[0m credentials file. If you recently regenerated your API key, you can retrieve it from [4;1mhttps://dashboard.infracost.io[0m. See [4;1mhttps://infracost.io/support[0m if you continue having issues. task: Failed to run task "plan": task: Failed to run task "infracost_diff": exit status 1
Idk, do I need to pass the api key in that line? •
- curl -fsSL <https://raw.githubusercontent.com/infracost/infracost/master/scripts/install.sh> | sh
l

little-author-61621

03/22/2024, 8:05 AM
@dazzling-airplane-3803 You shouldn’t need it for that curl Did you add this curl to your pipeline? It will help us debug:
Copy code
curl -i -H "User-Agent: infracost-debug-0fe936ed" -H "Content-Type: application/json" -H "X-Api-Key: $INFRACOST_API_KEY" <https://pricing.api.infracost.io/graphql>