The Midnight Cloud Bill: How Terraform Saved Us Lakhs by Destroying Dev Environments Every Night
By Srilakshmi Thulasiraman | Cloud Infrastructure Automation

✍️ 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 applybuilds everything from code. - Evening:
terraform destroyremoves 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 : Calculation as an Example
Let's say your dev environment costs ₹1,00,000 per month running 24/7.
| Setup | Hours Per Month | Approx. Cost |
|---|---|---|
| Always on | ~730 | ₹1,00,000 |
| Weekdays, 12 hrs/day | ~260 | ~₹36,000 |
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.
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:
- 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. - Store state remotely. Use an Azure Storage backend with locking so the scheduled pipeline and your teammates don't collide.
- Never auto-destroy production. Apply this only to dev and test, and use tags like
auto_delete = "true"to make it explicit. - Run
terraform planfirst when testing the pipeline for the first time. Read before you delete. - 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 authorGet 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.
Related blogs

SRE in Practice | Day 3: The SRE Mindset
Look beyond "Is the server up?" and ask whether the service works reliably for the people who depend on it. Concept, infrastructure example, and a hands-on lab.

Beyond the H100: The 5 NVIDIA Infrastructure Components Every AI Engineer Must Understand
Learn how networking, storage, and orchestration work together to stop your NVIDIA GPUs from sitting idle.

Azure AD Connect: Top 10 Production Mistakes to Avoid
What breaks hybrid identity, how to investigate it, and the controls worth putting in place before the next incident.

🚀 How Do GPUs Actually Talk to Each Other? The Hidden Network Powering AI at Scale
Your GPU may be incredibly powerful. But what happens when one GPU needs to communicate with hundreds of others?
Readers of this blog also read

SRE in Practice | Day 2: SRE vs DevOps
Two complementary perspectives on delivering and running reliable software. Concept, production example, and a hands-on release-mapping lab.
#chatgpt-for-seo
5 SEO Tasks to Do With ChatGPT (With Prompts)
Five SEO tasks ChatGPT handles reliably, each with a copy-paste prompt, the check its output needs, and the one prompt pattern that invents your data.

SRE in Practice: DAY 1 OF 30 What is SRE?
Why a running server does not always mean a working service. Concept, production example,and a safe hands-on lab.
#ml
AI Humanoid Robotics for Paddy Cultivation Robotics-as-a-Service Pay Per Acre
Why Agriculture? Food is one most essential needs of humanity, making agriculture a critical and high value industry with ever green demand. As the global...

💬 Comments (0)
Top · NewestSign in to comment