Course contentsShow
← Cloud and Infrastructure
Lesson 800 of 2,98915. Terraform in PracticeFree lesson

Root Module vs Child Modules

Distinguishing between the root configuration and reusable child modules in your infrastructure.

Root Module vs Child Modules

What you'll learn: You'll understand the fundamental distinction between your main Terraform configuration (root module) and reusable infrastructure components (child modules).

The Two-Level Module System

In Terraform, every configuration has a root module—this is your starting point, the directory where you run terraform init, plan, and apply. It's the main entry point for your infrastructure project.

Child modules are separate, self-contained configurations that the root module calls to create reusable infrastructure patterns. Think of the root module as your main program and child modules as libraries or functions you import.

Root Module: The Orchestrator

Your root module lives in your working directory and typically contains:

  • Provider configuration blocks
  • Variable declarations for user inputs
  • Calls to child modules (using module blocks)
  • Output values you want to expose
  • Sometimes direct resource definitions

The root module orchestrates everything—it's where execution begins and where you declare what gets deployed.

Child Modules: The Reusable Components

Child modules are folders (local or remote) containing their own .tf files. They:

  • Define a specific infrastructure pattern (like a VPC, database cluster, or app server setup)
  • Accept inputs through their own variables
  • Expose outputs for the root module to reference
  • Can be reused across projects or environments

Analogy: If your infrastructure is a house, the root module is the blueprint showing where everything goes, while child modules are pre-designed components like "standard bathroom" or "kitchen unit" that you place and customize.

The Relationship

The root module invokes child modules, passes them input variables, and receives their outputs. You never run Terraform commands directly in a child module directory—only in the root.

Key Takeaway: The root module is your main configuration where Terraform runs; child modules are reusable infrastructure components you call from the root to build organized, maintainable infrastructure.