Someone proposes `depends_on = [module.network]` on every other module "to be safe". Your take?
BeginnerScenarioModules and Code Structure
Answer
Situation read → Over-constraining the graph.
What I'd do →
- Remove blanket
depends_on. - Pass real outputs (
module.network.vpc_id) so dependencies are implicit and precise. - Keep explicit
depends_ononly for hidden dependencies, with a comment explaining why.
Why → Module-level depends_on makes every resource wait for every network resource, reduces parallelism and makes data sources inside defer to apply time.
Interview tip → Use references for ordering; use depends_on as a documented exception.
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