Infracost shows hourly and monthly cost estimates for a Terraform project. This helps developers, DevOps et al. quickly see the cost breakdown and compare different deployment options upfront.
To download and install the latest release:
Homebrew users can install by:
Generate a cost breakdown from a Terraform directory:
The Infracost GitHub action can be used to automatically add a PR comment showing the cost estimate
diff between a pull request and the master branch whenever Terraform files change.
Cost estimation of usage-based resources
Infracost distinguishes the price of a resource from its cost. Price is the per-unit price advertised by a cloud vendor. The cost of a resource is calculated by multiplying its price by its usage. For example, an EC2 instance might be priced at $0.02 per hour, and if run for 100 hours (its usage), it'll cost $2.00. Supported resources in Infracost will always show prices, but if a resource has a usage-based cost component, we can't show its cost as we don't know how much it'll be used. For example, an AWS Lambda resource shows zero hourly/monthly costs for duration and requests:
To solve this problem, the Infracost Terraform Provider can be used to describe usage estimates, which are used to calculate costs. As shown in the following example, it is easy to add this to Terraform projects. Instead of using cloud vendor cost calculators, spreadsheets or wiki pages, developers can track their usage estimates in their code, get cost estimates from them, and adjust them if needed. This enables quick "what-if" analysis to be done too; for example, what happens to the cost estimate if a Lambda function gets 2x more requests.
A Lambda function with usage estimates:
Infracost can now show hourly/monthly cost estimates:
To change the path to your
terraform binary you can set the
TERRAFORM_BINARY env variable:
Standard Terraform env variables such as
TF_CLI_ARGS can also be added if required:
Generate a cost breakdown from a Terraform plan JSON file:
How does it work?
Prices are retrieved using https://github.com/infracost/cloud-pricing-api. There is a demo version of that service deployed at https://pricing.infracost.io/graphql, which
infracost uses by default. On this service, spot prices are refreshed once per hour.
You can run
infracost in your terraform directories without worrying about security or privacy issues as no terraform secrets/tags/IDs etc are sent to the pricing service (only generic price-related attributes are used). Also, do not be alarmed by seeing the
terraform init in output, no changes are made to your terraform or cloud resources. Read-only AWS IAM creds can be used as a security precaution in CI pipelines that run
You can also deploy the price list API yourself and specify it by setting the
infracost_API_URL env variable or passing the