Better control over infracost integration
Currently to enable infracost, two things are necessary:
add the
infracostlabel to a stackset the
INFRACOST_API_KEYenvironment variable
In order to disable infracost for specific situations (e.g. local preview run or drift detection run), one has to manipulate the INFRACOST_API_KEY environment variable in order to prevent the call from happening.
It would be good to have better control over this, and not have to manipulate the INFRACOST_API_KEY environment variable (which I assume will still make the call to infracost, and Infracost will block it because of the bad API key).
```
[[ "$TF_VAR_spacelift_run_trigger" = "spacelift/drift_detection" || "$TF_VAR_spacelift_local_preview" = "true" ]] && export INFRACOST_API_KEY=disabled && export INFRACOST_WARN_ON_FAILURE=true || true
```
It would be nice to have an INFRACOST_ENABLED environment value that is possible to configure on the fly, which would prevent the calls from actually made and allowing us better control over the infracost integration.
- Workaround
- Problem
This request was merged into another request
Comments2
Black Breeze
Jan 7
Thanks for raising this @Joost Polley. Please let me dig a bit deeper into the problem. I’d like to start with two questions:
What are the situations in which you want to disable Infracost on a one-off basis, and why?
What would be your ideal workflow for these situations?
Thank you in advance!
Blue Goose
Jan 23
Hi @Marcin Wyszynski ! In our use case, we want infracost to not run during local previews and drift detection runs. During those situations they do not give us any value and we don’t want to burn our infracost credits.
An ideal workflow would be to decide during a run (like we do right now with the pre-init hook) to actually tell the runner to not run infracost. E.g. make it conditional, if the environment variable RUN_INFRACOST=false, then don’t have it run during the run. That’s more elegant than during the run manipulating the API key and still sending that specific data to the Infracost API.