Skip to main content

Get started

Infracost shows cloud cost estimates for Terraform. It lets DevOps, SRE and engineers 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.

If you're upgrading from an older version, see the v0.10 migration guide.

1. Install Infracost

Get the latest Infracost release:

brew install infracost

infracost --version # Should show 0.10.18

To upgrade Infracost, run brew update then brew upgrade infracost.

2. Get API key

Register for a free API key, which is used by the CLI to retrieve prices from 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 does not make any changes to your Terraform state or cloud resources.
infracost auth login

The key can be retrieved with infracost configure get api_key.

3. Show cost estimate breakdown

Infracost parses the project locally to determine resource types and quantities needed to calculate costs. The --path flag can point to a Terraform directory or plan JSON file.

# You can also: git clone
cd my-terraform-project
# Terraform variables can be set using --terraform-var-file or --terraform-var
infracost breakdown --path .

Example output:Infracost breakdown command


Infracost can also estimate usage-based resources such as AWS S3 or Lambda

4. Show cost estimate diff

  1. Generate an Infracost JSON file as the baseline:
  2. infracost breakdown --path . --format json --out-file infracost-base.json
  3. Edit your Terraform project. If you're using our example project, try changing the instance type:
  4. vim
  5. Generate a diff by comparing the latest code change with the baseline:
  6. infracost diff --path . --compare-to infracost-base.json

Example output:Infracost diff command

5. Monitor cost estimates

  1. The following command instructs the CLI to send its JSON output to Infracost Cloud. This is our SaaS product that builds on top of Infracost open source and works with CI/CD integrations (next step). It gives team leads, managers and FinOps practitioners dashboards, guardrails and centralized cost policies so they can help guide the team (e.g. switch AWS GP2 volumes to GP3).
  2. infracost upload --path infracost-base.json
  3. Log in to Infracost Cloud > Repos page to see the cost estimate.
Infracost Cloud dashboard showing pull request costs over the last 30 days

6. Add to your CI/CD

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

If you run into any issues, please join our community Slack channel, we'll help you very quickly 😄

Infracost pull request comment

If you use VS Code, checkout our VS Code extension to also see cost estimates right in your editor!

Infracost VS Code extension