Skip to main content

Infracost Integration

Infracost Integration

StackGuardian allows you to integrate your own Infracost API key for cost analysis of Terraform and OpenTofu Workflow runs. By bringing your own key (BYOK), you can connect to your organization's Infracost account directly, rather than using the default StackGuardian managed key.

How to Set Up Infracost Integration

  1. Obtain Your Infracost API Key

    • You will need an Infracost API key. This key is used for authenticating API requests from StackGuardian for cost estimation. If you do not have an API key, generate one from your Infracost account.
  2. Add Your API Key to StackGuardian

    • Go to your organization settings in the StackGuardian platform.
    • Find the Integrations section and go to Infracost Integration.
    • Enable the toggle for Infracost integration across the organization.
    • Enter your Infracost API key in the provided field.
    • Click Save.

All subsequent Terraform and OpenTofu Workflow runs will now use this Infracost API key for cost analysis.

info

Once saved, the Infracost API key cannot be retrieved again from the Organization settings.

info

If INFRACOST_API_KEY is set in the environment variables for a workflow, it will override the API key set in the Organization settings.

Frequently Asked Questions

Can I switch back to the default StackGuardian Infracost key?

Yes, if you disable the Infracost integration in the Organization settings, the default StackGuardian Infracost key will be used.

Will my Infracost API key be secure?

StackGuardian encrypts and stores your Infracost API key securely. Once set, it cannot be viewed again from the Organization settings. StackGuardian only accesses your Infracost API key while executing Terraform and OpenTofu workflow runs.

Why are my Infracost estimations in my workflow runs failing?
  • If Infracost integration is enabled at the organization level, first check if the API key is correct and valid.
  • If the API key is valid, check if the INFRACOST_API_KEY is set in the environment variables for the workflow. If the INFRACOST_API_KEY is set in the environment variables for the workflow with the failing runs, check if the value of this environment variable is correct.
  • If the API key is correct and valid, and the error still persists, contact StackGuardian support at support@stackguardian.io for further assistance.