Terraform Module Dependency Calculator
Estimate module dependency chain depth and flag circular dependency risk from module and edge counts.
Inputs
Total number of modules (root + child) in the configuration.
Total module-to-module dependency references (via module calls/outputs).
The longest path of module A → B → C → ... dependencies in the graph.
Longest Dependency Chain
5levels
Depth Risk
Moderate
Circular Dependency Risk
Moderate
Avg Edges per Module
1.59
Step by step
Longest dependency chain (user-provided)
maxChainDepth
= 5 levels
Avg edges per module
35 / 22
= 1.59
Edge-to-module ratio (circularity signal)
35 / 22
= 1.59
How it works
Module dependency depth is the longest chain of module-to-module references (via `module` blocks consuming another module's outputs). Formula: depth = longest_dependency_chain, measured by walking the module graph. Terraform's graph is required to be acyclic, so true circular dependencies fail at plan time — but a high edge-to-module ratio signals dense coupling that makes refactors risky and increases the chance of hitting one.
Formula
edge_to_module_ratio = dependency_edges / total_modules
- dependency_edges
- Total module-to-module dependency references
- total_modules
- Total number of modules in the configuration
Frequently Asked Questions
Can Terraform actually have circular module dependencies?
No — Terraform builds a directed acyclic graph (DAG) and will error out ("Cycle") if module references form a loop. This calculator's circular risk signal is a proxy for how close your coupling is to that failure mode, not a live cycle detector.
How do I visualize my actual module graph?
Run `terraform graph | dot -Tpng > graph.png` (requires Graphviz) to render the full resource/module dependency graph, or use `terraform graph -type=plan` for a plan-scoped view.
Why does dependency depth matter?
Deep chains mean a change to a foundational module (e.g. a shared networking module) ripples through many downstream modules before you see the final effect, making blast radius harder to reason about and applies slower.
How can I reduce module coupling?
Favor flatter, more independent modules with clear input/output contracts over deeply nested composition, and consider using remote state data sources instead of direct module nesting for cross-cutting concerns like shared VPCs.
You might also need
- Terraform Graph Complexity CalculatorCommonly used together
- Terraform Resource Count CalculatorCommonly used together
- Terraform Variable Size CalculatorCommonly used together
- Terraform Plan Complexity CalculatorCommonly used together
- Terraform Infrastructure Score CalculatorCommonly used together
- Terraform Drift CalculatorAlso in Terraform