Terraform Module Dependency Calculator
Map dependency depth and count across nested Terraform modules.
About Terraform Module Dependency Calculator
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
Worked example
With the default values below, Terraform Module Dependency Calculator returns Longest Dependency Chain of 5. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Total Modulesaccepts 1–1,000,000 modules
- 22 modules
- Dependency Edgesaccepts 0–10,000,000 edges
- 35 edges
- Longest Dependency Chainaccepts 0–1,000 levels
- 5 levels
Results
- Longest Dependency Chain
- 5 levels
- Depth Risk
- Moderate
- Circular Dependency Risk
- Moderate
- Avg Edges per Module
- 1.59
Step by step
- 1Longest dependency chain (user-provided)= 5 levels
- 2Avg edges per module= 1.59
- 3Edge-to-module ratio (circularity signal)= 1.59
Assumptions and limits
- The result is derived only from the 3 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to 2 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
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.
Related Calculators
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
