When you first start with Terraform, one question shows up almost immediately: how do I manage dev, staging, and prod without breaking something?
Terraform gives you two built-in ways to do it: folder-based environments and workspaces . I've used both on real Azure projects, so here's what each one looks like, where each one hurts, and which one I'd pick.
Table of Contents
The Problem: Why Environment Isolation Matters
Method 1: Folder-Based Environments
Method 2: Workspace-Based Environments
Folder vs Workspace: Quick Comparison
My Rule of Thumb (and a Hybrid Setup)
Quick Tip: What to Put in .gitignore
Conclusion
The Problem: Why Environment Isolation Matters
Picture this: you're cleaning up dev, you run terraform destroy , and a minute later you realize the terminal was pointed at prod.
That's the nightmare. You want your environments isolated , so a mistake in one can't touch another.β¦