Get cost hourly and monthly estimates for a Terraform project. Helps you quickly see the cost breakdown and compare different deployment options upfront.
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 a .tf file changes.
Currently this supports the following on-Demand and Spot pricing for the following AWS resources:
aws_instanceaws_ebs_volumeaws_ebs_snapshotaws_ebs_snapshot_copyaws_autoscaling_groupaws_db_instanceaws_elbaws_lbaws_nat_gateway
This does not yet support estimates for:
- any costs that are not specified in the Terraform configuration, e.g. S3 storage costs, data out costs.
- Non-Linux EC2 instances such as Windows and RHEL, a lookup is needed to find the OS of AMIs.
- Any non On-Demand pricing, such as Reserved Instances.
This is an early stage project, pull requests to add resources/fix bugs are welcome.
To download and install the latest release:
curl --silent --location "https://github.com/aliscott/infracost/releases/latest/download/infracost-$(uname -s)-amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/infracost-$(uname -s | tr '[:upper:]' '[:lower:]')-amd64 /usr/local/bin/infracostPrices are retrieved using https://github.com/aliscott/cloud-pricing-api. There is a demo version of that service deployed at https://pricing.infracost.io/graphql, which infracost uses by default. This is running on minimal infrastructure so is not guaranteed to always be available. 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. As a security precaution, read-only AWS IAM creds can be used.
You can also deploy the price list API yourself and specify it by setting the infracost_API_URL env variable or passing the --api-url option.
Generate a cost breakdown from a Terraform plan JSON file:
infracost --tfjson examples/terraform/plan.jsonTo generate the plan JSON file you can run:
terraform plan -out plan.save examples/terraform
terraform show -json plan.save > examples/terraform/plan.json
Generate a cost breakdown from a Terraform directory:
infracost --tfdir examples/terraformGenerate a cost breakdown from a Terraform plan file:
infracost --tfplan plan.save --tfdir examples/terraformTo change the path to your terraform binary you can set the TERRAFORM_BINARY env variable:
TERRAFORM_BINARY=~/bin/terraform_0.13 infracost --tfdir examples/terraform_0.13Install dependencies:
make depsRun the code:
make run ARGS="--tfdir <Terraform Dir>"Run tests:
make testBuild:
make buildPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

