When would you choose one root module with many modules over many small root modules (stacks)?
AdvancedScenarioModules and Code Structure
Answer
Situation read → Granularity of state is the real decision.
What I'd do →
- Single root when components are tightly coupled, deployed together and owned by one team.
- Separate roots when lifecycles, owners or blast radius differ, such as network vs app.
- Between roots, share through published outputs, not shared state files.
Why → One state gives atomic changes but slow plans and a large blast radius; many states give independence but need orchestration and contracts.
Interview tip → Frame it as lifecycle and ownership boundaries, not a file count.
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