Infracost - Cloud Cost Estimate for Terraform
What is Infracost?
Infracost provides Terraform cloud cost estimates. It enables DevOps, SRE, and engineers to see and understand cost breakdowns before making changes in the terminal or pull requests. This gives your team a safety net because costs can be discussed as part of the workflow. Infracost analyses the project on a local level to determine the resource types and quantities required to calculate costs.
Install Infracost
On Linux box install Infracost
root@infracost:~# curl -fsSL https://raw.githubusercontent.com/infracost/infracost/master/scripts/install.sh | sh
Downloading version latest of infracost-linux-amd64...
Validating checksum for infracost-linux-amd64...
Moving /tmp/infracost-linux-amd64 to /usr/local/bin/infracost (you might be asked for your password due to sudo)
Completed installing Infracost v0.10.19
root@infracost:~# infracost --version
Infracost v0.10.19
root@infracost:~#?
Create an account with Infracost
Access https://login.infracost.io/
In this case we are Signing up with your GitHub
Login with your GitHub credentials
Once you access the Infracost Dashboard, go to Org setting and copy the API Key
In your Linux Box terminal and set the API key and currency
root@infracost:~# infracost configure set api_key <KEY>
root@infracost:~# infracost configure set currency USD
Clone GitHub repo to get the cloud estimate for Cloud, in this case Google Cloud
root@infracost:~# git clone https://github.com/prayag-sangode/private-gke.gi
Cloning into 'private-gke'...
remote: Enumerating objects: 86, done.
remote: Counting objects: 100% (86/86), done.
remote: Compressing objects: 100% (80/80), done.
remote: Total 86 (delta 40), reused 12 (delta 4), pack-reused 0
Unpacking objects: 100% (86/86), 65.14 KiB | 844.00 KiB/s, done.t
Get the GCP estimate
root@infracost:~/private-gke# infracost breakdown --path . --show-skippe
Evaluating Terraform directory at .
? ? Downloading Terraform modules?
? ? Evaluating Terraform directory?
? ? Retrieving cloud prices to calculate costs?
Project: prayag-sangode/private-gke
?Name? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Monthly Qty? Unit? ? ? ? ? ? ? Monthly Cost?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
?google_compute_instance.default? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
?├─ Instance usage (Linux/UNIX, on-demand, e2-medium)? ? ? ? ? ? ? ?730? hours? ? ? ? ? ? ? ? ? ?$34.22?
?└─ Standard provisioned storage (pd-standard)? ? ? ? ? ? ? ? ? ? ? ?10? GB? ? ? ? ? ? ? ? ? ? ? ?$0.50?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
?google_container_cluster.primary? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
?└─ Cluster management fee? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 730? hours? ? ? ? ? ? ? ? ? ?$73.00?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
?google_container_node_pool.primary_nodes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
?├─ Instance usage (Linux/UNIX, preemptible, e2-medium)? ? ? ? ? ?2,190? hours? ? ? ? ? ? ? ? ? ?$13.35?
?└─ Standard provisioned storage (pd-standard)? ? ? ? ? ? ? ? ? ? ? 300? GB? ? ? ? ? ? ? ? ? ? ? $14.94?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
?module.cloud-nat.google_compute_router_nat.main? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
?└─ Data processed? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Monthly cost depends on usage: $0.045 per GB? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
?OVERALL TOTAL? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $136.01?
──────────────────────────────────
10 cloud resources were detected:
? 4 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file
? 6 were free:
? ? 1 x google_compute_address
? ? 1 x google_compute_firewall
? ? 1 x google_compute_network
? ? 1 x google_compute_router
? ? 1 x google_compute_subnetwork
? ? 1 x google_project_iam_member
root@infracost:~/private-gke#?d
You can also check the estimate in Infracost Dashboard
Conclusion: We have estimated the cost of GCP resource using Infracost in a few simple steps.
I hope you found this to be useful in some way. I’ll be back with some more interesting new Cloud and DevOps articles soon.