Skip to content

Latest commit

Β 

History

History
41 lines (28 loc) Β· 1.21 KB

File metadata and controls

41 lines (28 loc) Β· 1.21 KB

Terraform modules childs limits

We've all seen a root module with a child module that also has a child module.

TL;DR

As IaC guild we recommend that you have no more than 2 levels in your module hierarchy.

Limit the depth of the your modules' tree

We do not recommend to have a module tree that is too deep.

Why?

  • Debugging
    • It is hard to understand what is going on in the code -> the more child modules there are, the more difficult it will be to debug
  • Maintainability
    • Upgrade a root, child or grandchild modules may have an impact on the whole module tree (providers / terraform versions for instance)

Recommendation

We recommend to have a module tree that is no more than 2 levels deep like the following tree:

Ok πŸ‘

β”œβ”€β”€ root_module # <- Level 0
β”‚   β”œβ”€β”€ child_module_1 # <- Level 1
β”‚   β”‚   β”œβ”€β”€ grandchild_module_1 # <- Level 2
β”‚   β”œβ”€β”€ child_module_2 # <- Level 1

Not recommended ❌

β”œβ”€β”€ root_module # <- Level 0
β”‚   β”œβ”€β”€ child_module_1 # <- Level 1
β”‚   β”‚   β”œβ”€β”€ grandchild_module_1 # <- Level 2
β”‚   β”‚   β”‚   β”œβ”€β”€ grand_grandchild_module_1 # <- Level 3
β”‚   β”œβ”€β”€ child_module_2 # <- Level 1