Infracost calculates cloud costs based on Terraform. Cost estimates can be shown in the terminal or put in pull requests using our CI/CD integrations. This helps you understand the cost of services before you use them, and take action to optimize costs within your existing workflow.
If you're upgrading from an older version to
v0.9, please see the migration guide.
Assuming Terraform is already installed, get the latest Infracost release:
- macOS Homebrew
- macOS manual
If the version is old, please run
brew update then
brew upgrade infracost.
Download and unzip the latest release. 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.
Register for a free API key, which is used by the CLI to query the Cloud Pricing API, e.g. get prices for instance types. No cloud credentials or secrets are sent to the API.
The key is saved in
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:
Use our CI/CD integrations to automatically add pull request comments showing cost estimate diffs. This can also provide a safetynet as teams can discuss the cost impact of changes as part of their workflow.
infracost CLI has the following main commands. Use the
--path flag to point to either a Terraform directory or plan JSON file:
breakdown: show full breakdown of costs
diff: 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.
This is the simplest way to run Infracost. As shown below, any required Terraform flags can be passed using
--terraform-workspace flag can be used to define a workspace.
If the above method does not work for your use-case, you can use Terraform to generate a plan JSON file (as shown below), and point Infracost to it using
--path. In this case, cloud credentials are not needed by Infracost.
See the advanced usage guide for other usage options.
infracost breakdown --help to see the available options, which include:
Other useful commands:
infracost diff --helpto show diff of monthly costs between current and planned state
infracost output --helpto combine and output Infracost JSON files in different formats
infracost completion --helpfor shell completion scripts
infracost configure --helpfor global configs, including currency settings