Skip to main content

Terraform Cloud/Enterprise

Infracost is an official HashiCorp partner. We work together to ensure that Infracost can be used alongside Terraform Cloud and integrated into your workflow.

If you're a Terraform Cloud user, we recommend starting with Run Tasks. Run Tasks are not yet available in Terraform Enterprise, so you can use the details below to integrate using our other CI/CD integrations.

Terraform Cloud Run Tasks

Run Tasks is a beta Terraform Cloud feature that can be used to integrate Infracost into the Terraform Cloud pipeline directly. This enables Infracost to work with Terraform Cloud natively, meaning you do not need to install/upgrade our CLI into your CI/CD systems. As shown in the following screenshot, Infracost adds a comment showing the cost diff in Terraform Cloud's dashboard and you can click on the Details link to see the cost breakdown or diff in the same way you would see it when you run the CLI yourself.

Please email if you'd like to get access to the beta program.

To setup the integration:

  1. Generate a unique Infracost hook endpoint URL and HMAC key. These will be used in the next step.
  2. Follow the instructions for configuring a Run Task in Terraform Cloud. There are two steps you need to do: setup the integration, and enable it in your workspaces.
  3. After you've setup the integration, and enabled it on one or more of your workspaces, your runs will show the Infracost Run Task output and a link to the details; see example here.

Notes: As this integration is directly within Terraform Cloud, three things are not supported yet: pull request comments are not created; multiple currencies are not supported; the usage-file is not supported. Please create a GitHub issue or contact us if you're interested in these features. If you use GitHub, you can use the Infracost GitHub Actions to use those features (in addition to Cloud Run Tasks).

Terraform Cloud dashboardDetails link
Infracost running as a Run TaskInfracost details link

Infracost is a verified Terraform Cloud integration. Terraform Cloud only sends the plan JSON file to Infracost during cost estimation, no other secrets/logs are sent, and once the cost estimate is generated, the temporary plan file is deleted from our servers.

Terraform Cloud users

This section is only applicable for Terraform Cloud users.

Running Infracost locally requires no additional steps as your Terraform CLI config file is used to access the plan.

When running Infracost in CI/CD systems, you should either:

  1. Set the INFRACOST_TERRAFORM_CLOUD_TOKEN environment variable to a Team API Token or User API Token. This environment variable can also be set in the config file.
  2. Set the Terraform environment variable TF_CLI_CONFIG_FILE to the absolute path of your Terraform CLI config file.

Terraform Enterprise users

When running Infracost locally or in CI/CD systems, you should set both of the following environment variables. These environment variables can also be set in the config file.

  2. INFRACOST_TERRAFORM_CLOUD_HOST to your backend host, this overrides the default value.

Terraform workspaces

Terraform Cloud and Enterprise users who use multiple Terraform workspaces, can use an Infracost config file to define them; their results will be combined into the same breakdown or diff output.

If you'd like to select one workspace, you can do so by either:

  1. using the --terraform-workspace flag.
  2. setting the INFRACOST_TERRAFORM_WORKSPACE environment variable (this sets the TF_WORKSPACE internally).

Only set this for multi-workspace deployments, otherwise it might result in the Terraform error "workspaces not supported". If you see this error, try running unset INFRACOST_TERRAFORM_WORKSPACE and unset TF_WORKSPACE.