Refactoring Terraform: From One File to Modules
My three-tier AWS architecture worked. VPC, subnets, bastion host, app server, RDS, all deployed and running. But my main.tf was a flat file with everything mixed together. Security groups next to rou
blog.lalitbagga.com6 min read
Really enjoyed this post. Terraform starts off feeling simple when everything is in one file, but once the infrastructure grows, that approach becomes hard to maintain very quickly. I like how you showed the practical path from a single-file setup to a module-based structure instead of just talking about theory.
What stood out to me most was the readability and reusability angle. Modules do add a little upfront structure, but in the long run they make the codebase much easier to understand, scale, and hand over to another engineer without confusion.
This is the kind of refactoring that doesn’t always feel urgent at first, but once you’ve lived with a messy Terraform codebase, you immediately see the value. Solid write-up.