Interview Prep/Terraform/Dependencies, Cycles and Providers

A cycle appears only after adding `depends_on = [module.app]` to a module. The error lists dozens of nodes.

IntermediateTroubleshootingDependencies, Cycles and Providers
Answer

Likely causes → Module-level depends_on makes every resource and data source in the module depend on everything in the other module. If any value flows back (an output of this module is used by module.app), you get a cycle.

Diagnose → The cycle list contains nodes from both modules; check which outputs cross between them.

Fix → Remove the module depends_on and pass the actual values (IDs, ARNs) as inputs; Terraform then infers precise dependencies.

Prevent → Treat module depends_on as a last resort; it also delays data sources and causes "known after apply" noise.

All Terraform questions Roadmap: Terraform

More on Dependencies, Cycles and Providers