Skip to main content

Getting started

Infracost shows cloud cost estimates for Terraform. It enables DevOps, SRE and engineers to see a cost breakdown and understand costs before making changes, either in the terminal or pull requests. This provides your team with a safety net as people can discuss costs as part of the workflow.

Quick start

1. Install Infracost

Assuming Terraform is already installed, get the latest Infracost release:

brew install infracost

infracost --version # Should show v0.9.16

If the version is old, please run brew update then brew upgrade infracost.

2. Get API key

Register for a free API key, which is used by the CLI to query our Cloud Pricing API, e.g. get prices for instance types. No cloud credentials or secrets are sent to the API and you can also self-host it.

infracost register

The key can be retrieved with infracost configure get api_key.

3. Run it

Infracost does not make any changes to your Terraform state or cloud resources. Run Infracost using our example Terraform project to see how it works. The CLI commands page describes the options for --path, which can point to a Terraform directory or plan JSON file.

git clone https://github.com/infracost/example-terraform.git
cd example-terraform/sample1

# Play with main.tf and re-run to compare costs
infracost breakdown --path .

# Show diff of monthly costs, edit the yml file and re-run to compare costs
infracost diff --path . --sync-usage-file --usage-file infracost-usage.yml

Screenshots of example outputs are shown below.

4. Add to CI/CD

Use our CI/CD integrations to add cost estimates to pull requests. This provides your team with a safety net as people can understand cloud costs upfront, and discuss them as part of your workflow.

Other CI/CD systems can be supported using our Docker images. If you run into any issues, please join our community Slack channel, we'd be happy to help!

Screenshots

Infracost running in pull requests:

Infracost pull request comment

Show full breakdown of costs, see the CLI commands page for the other commands.

Infracost breakdown command

Show diff of monthly costs between current and planned state:

Infracost diff command