Getting started
Infracost shows cloud cost estimates for infrastructure-as-code projects such as Terraform. It helps developers, devops and others to quickly see a cost breakdown and compare different options upfront.
If you're upgrading from an older version to v0.8
, please see the migration guide.
#
Installation#
1. Install InfracostAssuming Terraform is already installed, get the latest Infracost release:
- macOS Homebrew
- macOS manual
- Linux
- Docker
- Windows
Subsequent updates can be installed in the usual way: brew upgrade infracost
(you might need brew update
first if your brew isn't up-to-date)
Download and unzip the latest release. Rename the file infracost-windows-amd64
to infracost.exe
, then run it from the Command Prompt or Powershell using .\infracost.exe --no-color
alongside other required commands/flags (color output has a bug we need to fix on Windows). You should also move the exe file to a folder that is in your PATH
environment variable, e.g. C:\Windows
.
#
2. Get API keyRegister for a free API key:
The key is saved in ~/.config/infracost/credentials.yml
.
#
3. Run itRun Infracost using our example Terraform project to see how it works:
Use our CI/CD integrations to automatically add pull request comments showing cost estimate diffs.
#
UsageAs mentioned in the FAQ, no cloud credentials, secrets, tags or resource identifiers are sent to the Cloud Pricing API. That API does not become aware of your cloud spend; it simply returns cloud prices to the CLI so calculations can be done on your machine. Infracost does not make any changes to your Terraform state or cloud resources.
The infracost
CLI has the following main commands. Use the --path
flag to point to a Terraform directory or plan JSON file:
breakdown
: show full breakdown of costsdiff
: show diff of monthly costs between current and planned state
If your repo has multiple Terraform projects or workspaces, use an Infracost config file to define them; their results will be combined into the same breakdown or diff output.
#
Terraform directoryAs shown below, any required Terraform flags can be passed using --terraform-plan-flags
. The --terraform-workspace
flag can be used to define a workspace.
Internally Infracost runs Terraform init, plan and show; init requires cloud credentials to be set, e.g. via the usual AWS_ACCESS_KEY_ID
or GOOGLE_CREDENTIALS
environment variables.
#
Terraform plan JSONPoint to a Terraform plan JSON file using --path
. This implies that Terraform init
has been run, thus Infracost just runs Terraform show
, which does not require cloud creds to be set.
See the advanced usage guide for other usage options.
#
Useful optionsRun infracost breakdown --help
to see the available options, which include:
The infracost diff --help
and infracost output --help
commands show related options.