Cost Estimationยป
The Infracost integration allows you to run an Infracost breakdown during Spacelift runs, providing feedback on PRs, and allowing you to integrate cost data with plan policies.
This allows you to understand how infrastructure changes will impact costs, and to build automatic guards to help prevent costs from spiraling out of control.
Setting up the integrationยป
To enable Infracost on any stack you need to do the following:
- Add the
infracost
label to the stack. - Add an
INFRACOST_API_KEY
environment variable containing your Infracost API key.
Info
Creating a context for your Infracost API key means you can attach your key to any stacks that need to have Infracost enabled.
If Infracost has been configured successfully, you should see some messages during the initialization phase of your runs indicating that Infracost is enabled and that the environment variable has been found:
Additional CLI Argumentsยป
If you need to pass any additional CLI arguments to the Infracost breakdown command, you can add them to the INFRACOST_CLI_ARGS
environment variable. Anything found in this variable is automatically appended to the command. This allows you to do things like specifying the path to your Infracost usage file.
Ignore Failuresยป
By default, a failure executing Infracost, or a non-zero exit code being returned from the command will cause runs to fail.
This behavior can be changed by setting the INFRACOST_WARN_ON_FAILURE
environment variable to true
. When enabled, Infracost errors will produce a warning message, but will not cause run failures.
Using the integrationยป
Once the integration is configured, Spacelift will automatically run Infracost breakdowns during the planning and applying stages. The following sections explain the functionality provided by the integration.
Pull Requestsยป
Spacelift automatically posts the usage summary to your pull requests once Infracost is enabled:
Plan Policiesยป
Spacelift includes the full Infracost breakdown report in JSON format as part of the input to your plan policies. This is contained in third_party_metadata.infracost
. The following shows an example plan input:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
This means that you can take cost information into account when deciding whether to ask for human approval or to block changes entirely. The following policy provides a simple example of this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Resources Viewยป
Infracost provides information about how individual resources contribute to the overall cost of the stack. Spacelift combines this information with our resources view to allow you to view the cost information for each resource: