Infracost: Real-life cost of cloud infrastructure used during training

Felipe Lujan
6 min readAug 24, 2022

Ever wondered how much the cloud infrastructure you used while studying would cost in real life? In this very opinionated article, I explore the cost of those Kubernetes Clusters, virtual machines, and networks using Infracost. I also provide a refresher on some of the cost benefits specific to Google Cloud, Microsoft Azure, and Amazon Web Services.

It’s not rare to find cleanup steps at the end of guided tutorials to stop charges against your account (or your employer’s) after deploying a handful of resources. This guide, for instance, wraps up with a few handy steps in the Azure Portal to get rid of the Resource Group containing the demo infrastructure used throughout the tutorial.

Similarly, I introduced cleanup steps in my previous contributions to Google Cloud’s community contributions after a Google employee strongly suggested doing so before approving my pull request. Cloud vendors really don’t want you to pay for what you no longer need.

We need to talk about Qwicklabs if we’re on the topic of preventing newbies from generating unwanted spending. The concept is relatively simple:

  1. In Qwiklabs, you get an ephemeral Google Email Account to log into the Google Cloud Console.
  2. You use this temporary account to follow the Guided tutorials and deploy a bunch of stuff in Google Cloud.
  3. After a few hours, the email account self-destructs, taking the cloud infrastructure with it.

On the other hand, however, Qwicklabs requires buying credits and is not multi-cloud.

There is a similar — also not free — multi-cloud service that offers Linux Virtual Machines in addition to temporary GCP, AWS, and Azure accounts; ready to be corrupted, experimented on, and misconfigured in any way imaginable by pros and rookies alike.

Introducing: L̶i̶n̶u̶x̶ ̶A̶c̶a̶d̶e̶m̶y̶ A cloud guru.

Just don’t try to mine crypto or 1-up the system in any other way. They will notice!!!

These complimentary services do not solve the root issue, though. Engineers are not warned of the costs of using cloud services with the same frequency as they hear about computing speed, ease of use, and the countless benefits of bleeding edge tech in the cloud.

Of course, I am not suggesting that licensing, management fees and pay-per-use costs are intentionally obscured away from the customers of the three leading cloud vendors; in fact:

  • Google has exceptional documentation about the pricing model for GCP. Example you sign a committed use contract for 8 CPU cores, but you ended up using 12 CPU cores in a given month; here, you get the committed use discount on 8 Cores, and the remaining four are eligible for sustained use discount. Example 2: You sign a contract for 8 CPU cores for a year but realize that you'll need only four cores/month on average; here, you can share your committed use contract with another project in your GCP billing account. Example 3. You use an n1-standard-4 machine (4 vCPU), but you need an upgrade two weeks into the month and switch to n1-standard-16 (16vCPU). In this scenario, both portions are eligible for a 10% discount for sustained use discount.
  • With an exciting twist, AWS has a feature similar to committed use discounts called Reserved Instances (RIs); customers can resell some unused Amazon EC2 Standard RIs in the RI Marketplace; of course, conditions apply.
  • Azure Reservations provide instance size flexibility, meaning that you can change the vCPU and memory specs of some of your VMs and still be eligible for a discounted price.

Having explained my point, let’s explore the operational cost of typical infrastructure deployments. BUT! to make matters more exciting and replicable on your end, I will define Infrastructure as Code (IaC) in Terraform and Infracost. The former is a reasonably standardized technology to define multi-cloud infrastructure. The latter is a recent and brilliant tool that understands Terraform’s IaC and displays infrastructure code in the command line, pull requests, or directly in your IDE.

I will skip all the download, install and configure sections, check this link out for that. Let’s move straight to the numbers $$$.

From Terraform’s tutorials, the code for running a t2.micro Linux VM during one month:

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.16"
}
}
required_version = ">= 1.2.0"
}
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "app_server" {
ami = "ami-830c94e3"
instance_type = "t2.micro"
tags = {
Name = "ExampleAppServerInstance"
}
}

Returns this estimate (in August 2022)

Notice the resource type (aws_instance) and name (app_server) above the cost breakdown.

Another example this time in Microsoft Azure.

From this guide in Linux Acad…. A Cloud Guru, I will deploy:

  • A 2-VM scale set
  • A Jumphost VM, with its network interface and public IP.
  • A virtual network, subnet, Load Balancer, and Load balancer Rule.

Some of the aforementioned resources generate charges. According to Infracost, the monthly cost of using this infrastructure adds up to:

Finally, let's borrow an example from Qwiklabs.

Lab GSP233 will provide you with a Google Cloud account ready to deploy a GKE cluster and a Load Balancer service inside.

Before we repeat the same exercise with Infracost, let's first get an estimate from Google Cloud Pricing Calculator. The planned infrastructure is:

  • 1 regional Google Kubernetes Engine Cluster in the uswest-1 region made out of:
  • 3 Google Compute Engine non-preemptive VMs (E2-medium), each with 100Gb worth of standard persistent disk.
  • 1 Static external IP address.
Google Cloud Pricing Calculator: The "official" tool to benchmark against.

Some important considerations to note here:

  • This GKE cluster is not eligible for free GKE service fee; because it is not a zonal cluster; instead, it is a regional cluster with nodes running in three different zones for improved resiliency.
  • By default, when you create a LoadBalancer service in a GKE cluster. A Load Balancer service will be created in GCP. Inbound and outbound data is charged per GB. This example accounts for 0Gb of data processed.
  • The estimation accounts for 730 hours/month of VM utilization; that's 100% of the month! This means that this estimation qualifies for sustained use discount on E2-medium VMs.

Now, the developer-friendly cost estimation with Infracost.

0.01 USD off. I approve

As a final note, the Infracost VScode extension shows handy cost estimates directly on top of your terraform resource definition, like so.

As final comment; no, i am not sposored by Infracost. I genuinely think that it provides valuable information that engineers don't see very often. I hope that you learned something valuable today.

See you later.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Felipe Lujan
Felipe Lujan

Written by Felipe Lujan

Google Developer Expert — Google Cloud.

No responses yet

Write a response