Infracost has a CLI and a Cloud Pricing API backend service, as well as many CI/CD integrations. The CLI parses the Terraform plan JSON file to find supported resources and uses cost-related parameters to find any applicable prices for that resource. The Cloud Pricing API returns the prices, which the CLI then uses to calculate the monthly costs. The results can be output in table, HTML or JSON format.
Infracost works with Terraform v0.12 and above.
To change the path to the
terraform binary, set the
INFRACOST_TERRAFORM_BINARY environment variable:
Terragrunt users should see this page.
That depends on how you run Infracost, since we run Terraform internally, which sometimes needs cloud credentials:
- When Infracost is run against a Terraform directory, Terraform will need access to cloud credentials, e.g. when running
terraform plan. These commands are only used to produce plan JSON files and no changes are made to your Terraform state or cloud resources.
- When Infracost is run against a Terraform plan JSON file, cloud credentials are not needed.
Infracost gets prices from the Cloud Pricing API, which we continually update with the latest cloud vendor prices.
No cloud credentials or secrets are sent to the Cloud Pricing API. Infracost does not make any changes to your Terraform state or cloud resources.
The Cloud Pricing API needs the relevant data to return a unique cloud price point. We also send the count of Terraform resource types to the Cloud Pricing API to enable us to better prioritize support for new resources. Additional context such as the operating system, Terraform version, type of CI system, and Infracost version are also sent alongside error tracking events so we can identify and fix issues quickly.
Here is an example request to the Cloud Pricing API for a t3.micro instance and the returned response:
Yes! Please email firstname.lastname@example.org for details.
The key differences are:
- Infracost supports over 140 resources. Terraform Cloud supports 43 resources.
- Infracost can be used to model usage-based resources and do what-if analysis.
- Infracost has a CLI tool that can be used in your terminal or integrated into your workflows regardless of the source control and CI/CD system being used.
- Infracost can be used with Terragrunt.
- Infracost can output HTML reports or JSON and be used alongside other tools.