Get started
Infracost shows cloud cost estimates for Terraform. It lets engineers see a cost breakdown and understand costs before making changes, either in the terminal, VS Code or pull requests. This provides your team with a safety net as people can discuss costs as part of the workflow.
1. Install Infracost
Get the latest Infracost release:
- macOS brew
- macOS/Linux manual
- Windows chocolatey
- Windows manual
- Docker
brew install infracost
infracost --version # Should show 0.10.29
To upgrade Infracost, run brew update
then brew upgrade infracost
.
The easiest way is to use our install script:
# Downloads the CLI based on your OS/arch and puts it in /usr/local/bin
curl -fsSL https://raw.githubusercontent.com/infracost/infracost/master/scripts/install.sh | sh
Or you can install it manually:
- Download the archive for your platform from our releases.
- Unarchive and copy it to one of the directories in your
$PATH
, e.g./usr/local/bin
:tar xzf infracost-linux-amd64.tar.gz -C /tmp
mv /tmp/infracost-linux-amd64 /usr/local/bin/infracost - Check that it works correctly:
infracost --version # Should show 0.10.29
choco install infracost
infracost --version # Should show 0.10.29
To upgrade Infracost, run choco upgrade infracost
.
Download and unzip the latest release. Run it from the Command Prompt or Powershell using .\infracost.exe
alongside other required commands/flags. You should also move the exe file to a folder that is in your PATH
environment variable, e.g. C:\Windows
.
docker pull infracost/infracost:ci-latest
docker run --rm \
-e INFRACOST_API_KEY=see_following_step_on_how_to_get_this \
-v $PWD/:/code/ infracost/infracost:ci-latest breakdown --path /code/
# Add other required flags/envs, e.g. --terraform-var-file or --terraform-var
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.
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 should point to your Terraform directory.
# You can also: git clone https://github.com/infracost/example-terraform
cd my-terraform-project
# Terraform variables can be set using --terraform-var-file or --terraform-var
infracost breakdown --path .
Example output:
Infracost can also estimate usage-based resources such as AWS S3 or Lambda
4. Show cost estimate diff
- Generate an Infracost JSON file as the baseline:
- Edit your Terraform project. If you're using our example project, try changing the instance type:
- Generate a diff by comparing the latest code change with the baseline:
infracost breakdown --path . --format json --out-file infracost-base.json
vim main.tf
infracost diff --path . --compare-to infracost-base.json
Example output:
5. See costs in dashboard
- 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 enables team leads, managers and FinOps practitioners to setup tagging policies, guardrails and best practices to help guide the team. For example, you can check for required tag keys/values, or suggest switching AWS GP2 volumes to GP3 as they are more performant and cheaper.
- Log in to Infracost Cloud > Visibility > Repos page to see the cost estimate.
infracost upload --path infracost-base.json

6. Add to your CI/CD
Use our 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 😄

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