ByteBlogby CareerByteCode

The Midnight Cloud Bill: How Terraform Saved Us ₹X Lakhs by Destroying Dev Environments Every Night

By Srilakshmi Thulasiraman | Cloud & Linux Engineer | Azure • AWS • GCP

The Midnight Cloud Bill: How Terraform Saved Us ₹X Lakhs by Destroying Dev Environments Every Night

✍️ Translate this blog into Hindi, Tamil or Telugu

The Cloud Bill That Made Everyone Go Quiet

Every month, the cloud bill arrives, and every month someone asks the same question: "Why is dev so expensive?"

Here's the uncomfortable truth. Your development and test environments are used maybe 9 hours a day, 5 days a week. That's about 45 hours out of 168 in a week. But the VMs, disks, gateways, and databases run all 168 hours.

🛍️✨ From the author · ByteStoreCareer gap analysis and Mentoring - Basic Plan₹299View offer →

You are paying for roughly 70% idle time. Nobody is using those machines at 2 AM on a Sunday, but the meter is still running.

The fix isn't to ask people to "remember to switch things off." People forget. The fix is to make your infrastructure disposable, and that's where Terraform comes in.

The Idea: Treat Dev Like a Hotel Room, Not a House

You don't pay rent on a hotel room when you're not in it. You check in, use it, and check out.

With Terraform, your dev environment works the same way:

  • Morning: terraform apply builds everything from code.
  • Evening: terraform destroy removes it all.

Because the environment is defined in code, rebuilding is quick and identical every single time. Nothing is lost, because the code is the environment, not the running machines.

What It Looks Like in Practice

Here's a simplified Azure example:

variable "environment" {
  default = "dev"
}

variable "vm_count" {
  default = 2
}

resource "azurerm_resource_group" "dev" {
  name     = "rg-app-${var.environment}"
  location = "Central India"

  tags = {
    environment = var.environment
    auto_delete = "true"
    owner       = "platform-team"
  }
}

resource "azurerm_linux_virtual_machine" "web" {
  count = var.vm_count
  name  = "vm-web-${count.index}"
  size  = "Standard_B2s"
  # network, image and admin settings...
}

Everything sits inside one resource group, so a destroy cleans up everything in one go, with no orphaned disks or forgotten public IPs.

Then automate it with a scheduled pipeline (Azure DevOps or GitHub Actions):

  • 8:00 AM, Mon-Fri: pipeline runs terraform apply -auto-approve
  • 8:00 PM, Mon-Fri: pipeline runs terraform destroy -auto-approve

Weekends: nothing runs at all.

The Math (Use Your Own Numbers Here)

Let's say your dev environment costs ₹1,00,000 per month running 24/7.

SetupHours Per MonthApprox. Cost
 Always on  ~730 ₹1,00,000
 Weekdays, 12 hrs/day ~260 ~₹36,000
🛍️✨ From the author · ByteStoreLinux & Cloud Administration Consultation | AWS & Azure Infrastructure Support₹499View offer →

That's a saving of roughly ₹64,000 per month, or over ₹7 lakhs per year, from one environment. Multiply by dev, QA, and UAT, and the number gets serious.

Note: these figures are illustrative. Replace them with your real Azure Cost Management numbers before publishing. Real data makes the story far more credible.

The Hidden Bonus: Fewer "Works on My Machine" Problems

A fresh environment every morning means no leftover junk: no mystery config changes from last week, no half-installed packages, no manual tweaks nobody documented.

If something works in dev today, it works because the code says so. That makes promoting to higher environments far more predictable.

Things to Watch Out For

Not everything should be destroyed blindly. Here's what I'd recommend:

  1. Keep data safe. Databases and storage with important data should live in a separate Terraform configuration (or use prevent_destroy), or be restored from backups or seed scripts.
  2. Store state remotely. Use an Azure Storage backend with locking so the scheduled pipeline and your teammates don't collide.
  3. Never auto-destroy production. Apply this only to dev and test, and use tags like auto_delete = "true" to make it explicit.
  4. Run terraform plan first when testing the pipeline for the first time. Read before you delete.
  5. Keep secrets out of code. Use Key Vault and pipeline variables.

The Takeaway

Terraform isn't only about building infrastructure faster. It's about spending smarter. When your environments are code, they stop being precious pets you must keep alive and become cattle you can create and remove on demand.

The best part is that this one habit pays for itself, and your finance team will thank you.

Your challenge this week: pick one dev environment, put it in a single resource group, write it in Terraform, and try a destroy and rebuild cycle. Then compare the cost next month.

Have you ever been shocked by a cloud bill? Share your story in the comments.

🛍️ Srilakshmi T's shelf

Courses, cohorts and more from the author
Srilakshmi T
Written by Srilakshmi T
A Cloud and Linux SRE Engineer where reliability, automation, and cloud operations excellence are key priorities
🏅 Rookie writer

Cloud & Linux SRE Engineer with 5 years of IT experience, including Linux/Unix system administration and cloud platforms (AWS & Azure). Strong expertise in production support, reliability engineering, monitoring, automation, patching, and incident management across large-scale e

Visit my ByteStoreFreelancer - Cloud Engineer
Open to workHire me →

Get Srilakshmi T's next blog by email

One email a week when they publish. Add the weekly Best of ByteBlog too. No spam, unsubscribe with one click.

We email you once to confirm. By subscribing you agree to the privacy policy.

💬 Comments (0)

Top · Newest

Sign in to comment

🛍️✨ From the author · ByteStoreCareer gap analysis and Mentoring - Basic Plan₹299View offer →