Getting started
Infracost shows cloud cost estimates for Terraform projects. It helps developers, devops and others to quickly see the cost breakdown and compare different options upfront.
#
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
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 flags/commands (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 keyUse our free Cloud Pricing API by registering for an API key:
The key is saved in ~/.config/infracost/config.yml
. If you prefer, you can run your own Cloud Pricing API.
#
3. Run itRun Infracost using our example Terraform project to see how it works.
Our CI/CD integrations can be used to automatically add a comment showing the cost estimate diff
between a pull request and the master branch.
#
Usage methodsInfracost can be run with different options depending on the use-case. As mentioned in the FAQ, you can run Infracost in your Terraform directories without worrying about security or privacy issues as no cloud credentials, secrets, tags or Terraform resource identifiers are sent to the open-source Cloud Pricing API. Infracost does not make any changes to your Terraform state or cloud resources.
#
1. Terraform directoryThis is the default method. Point to the Terraform directory using --tfdir
and pass any required Terraform flags using --tfflags
. Internally Infracost runs Terraform init
, plan
and show
; init
requires cloud credentials to be set, e.g. via the usual AWS_ACCESS_KEY_ID
environment variables. This method works with remote state too.
#
2. Terraform state filePoint to the Terraform directory using --tfdir
and instruct Infracost to use the Terraform state file using --use-tfstate
. This implies that you have already run Terraform init
, thus Infracost just runs Terraform show
, which does not require cloud creds to be set. This method takes less time to run compared with method #1 and also works with remote state.
#
3. Terraform plan JSONPoint to an existing Terraform plan JSON file using --tfjson
. This implies that the user has already run Terraform init
, thus Infracost just runs Terraform show
, which does not require cloud creds to be set.
#
4. Terraform plan filePoint to the Terraform directory and use the Terraform plan. This implies that the user has already run Terraform init
, thus Infracost just runs Terraform show
, which does not require cloud creds to be set. This method works with remote state too.
#
Useful optionsRun infracost --help
to see the available options, which include: