Estimating Cloud Costs with Infracost/Terraform
The Problem
Before, if you wanted to know how expensive your cloud infrastructure would be, you would have to use a tool like Azureβs Pricing Calculator. Itβs a nice tool that Azure provides, but it can involve a lot of tedious manual calcuations. Wouldnβt it be nice if you could automate price estimates?
Enter Infracost
Infracost uses your Terraform code to tell you how much your resources will cost before deploying them. This allows you to skip tedious calculations, avoid surprise billing, as well as include budgeting in your Terraform code pipelines!
Infracost is
- Incredibly easy to use
- built to work with AWS, Azure, and Google Cloud
- Runs on Mac OS, Linux, and Windows *Itβs Free!
Installation
Install for Mac OS
brew install infracost
infracost --version # Should show 0.10.33
Install for Linux
# 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
Install with Chocolatey
choco install infracost
infracost --version # Should show 0.10.33
Get API key
Next, you have to register for a free API key.
infracost auth login
You will be prompted to register for a free API key. Once registered, click on βOrg Settingsβ to obtain your API key. Then set it on the CLI:

infracost configure set api_key MY_API_KEY
You can then get your api key with the following command.
infracost configure get api_key
Running a Cost Breakdown
cd ~/code/terraform-code/
infracost breakdown --path .
You will get an estimated breakdown of costs based on your defined Terraform resources.
Evaluating Terraform directory at .
β Downloading Terraform modules
β Evaluating Terraform directory
β Retrieving cloud prices to calculate costs
Project: Timothy-Pulliam/aks-terraform-dev
Name Monthly Qty Unit Monthly Cost
azurerm_application_gateway.this
ββ Gateway usage (basic v2) 730 hours $146.00
ββ V2 capacity units (basic) 730 CU $5.84
azurerm_key_vault_certificate.this
ββ Certificate renewals Monthly cost depends on usage: $3.00 per requests
ββ Certificate operations Monthly cost depends on usage: $0.03 per 10K transactions
azurerm_postgresql_flexible_server.this
ββ Compute (GP_Standard_D8ds_v4) 730 hours $519.76
ββ Storage 512 GB $58.88
ββ Additional backup storage Monthly cost depends on usage: $0.095 per GB
azurerm_private_dns_zone.db
ββ Hosted zone 1 months $0.50
azurerm_public_ip.appgw_pip
ββ IP address (static) 730 hours $3.65
OVERALL TOTAL $734.63
ββββββββββββββββββββββββββββββββββ
18 cloud resources were detected:
β 5 were estimated, 3 of which include usage-based costs, see https://infracost.io/usage-file
β 13 were free, rerun with --show-skipped to see details
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ³βββββββββββββββ
β Project β Monthly cost β
β£ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ«
β Timothy-Pulliam/aks-terraform-dev β $735 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ»βββββββββββββββ
More Features
Infracost can do so much more, including
- Save cost breakdowns as JSON files
- Diff your current breakdown to previous saved JSON file
- Integrate billing into your CI/CD pipelines
- Display your breakdown in a web-based graphical dashboard by uploading a JSON file to Infracost Cloud
infracost upload --path infracost-base.json

And so much more.
Check out the Docs for more information
https://www.infracost.io/docs/
or ask questions on the Infracost Community Slack channel