Hey, you probably get that question often, when I ...
# help
d
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
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
Hey, yes I did, but I get the exact same error.
Also checked again, spelling is correct.
l
@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
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
Okay thank you @dazzling-airplane-3803!
d
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
@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>