In this blog, we will see a new tool called Infracost, which helps provide expected cloud cost estimates based on Terraform code. We will cover the installation and demonstrate how to use this tool.

Infracost :  It provides cloud cost projections from Terraform. It enables engineers to view a detailed cost breakdown and comprehend expenses before implementions.

Requirement :

1. One window/Linux VM


3.Terraform examples

Step 1 : infracost installation,

For Mac, use below brew command to do the installation,

brew install infracost

For other Operating systems, follow below link,

Step 2 : Infracost configuration,

We need to set up the Infracost API key by signing up here,

Once logged in, visit the following URL to obtain the API key,

Next, open the terminal and set the key as an environment variable using the following command,


or You can log in to the Infracost UI and grant terminal access by using the following command,

# infracost auth login

NoteInfracost will not send any cloud information to their server.

Step 3 : Infracost validation

Next, We will do the validation. For validation purpose i have cloned below github repo which contains terraform examples.

# git clone

# cd terraform-azure-examples/code/01-hello-world

try infracost by using below command to get the estimated cost for a month,

# infracost breakdown --path .

To save the report in json format and upload to infracost server, use below command,

# infracost breakdown --path . --format json --out-file infracost-demo.json

# infracost upload --path infracost-demo.json

In case we plan to upgrade the infrastructure and need to understand the new cost, execute the following command to compare it with the previously saved output from the Terraform code path.

# infracost diff --path . --compare-to infracost-demo.json

Thanks for reading!! We have installed infracost and experimented with examples.


Post a Comment

Previous Post Next Post