Teams complain a "VPC module" has 90 variables and still doesn't do what they need. How do you fix the design?
IntermediateScenarioModules and Code Structure
Answer
Situation read → A God module that tries to cover every case.
What I'd do →
- Split by concern: network core, NAT, endpoints, flow logs.
- Offer opinionated defaults and a few feature flags.
- Group optional settings in typed objects.
- Add
examples/showing the three common shapes.
Why → Smaller modules compose; each has a small interface, and consumers swap parts without forking.
Interview tip → If a module needs a count for every resource, it's trying to do too much.
More on Modules and Code Structure
When do you turn a block of resources into a module, and when do you leave it alone?BeginnerHow do you consume a community module like `terraform-aws-modules/vpc/aws` responsibly?BeginnerAn ECS service module needs the VPC and subnets created by a network module. How do you wire them together?IntermediateHow would you lay out a repo that deploys the same stack to dev, stage and prod?IntermediateHow do you release a shared module so consumers can upgrade at their own pace?IntermediateA module needs to deploy to a second region. Why does putting a provider block inside the module cause trouble?Advanced