A monorepo has 40 stacks. How do you structure layers and blast radius?
AdvancedScenarioModules and Code Structure
Answer
Situation read → One giant state means slow plans and a huge blast radius.
What I'd do →
- Layer by change frequency and ownership:
foundation(accounts, IAM, DNS),network,data,platform(EKS),apps. - One state per layer per environment.
- Pass values downward through SSM parameters or remote state outputs.
- Gate each layer with CODEOWNERS and separate apply roles.
Why → Slow-changing, high-impact layers get strict review; fast-changing app layers deploy often and can't break the network.
Interview tip → Say how apps discover infrastructure: data sources and tags, not hardcoded IDs.
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