Refactoring Terraform into modules changes structure, but Terraform evaluates identity through state addresses.
This lesson explains how module structure introduces ownership boundaries, how parents interact with child modules, and why moving a resource into a module changes its address.
What you will learn
- Child modules create isolated ownership boundaries
- Inputs define what the parent is allowed to control
- Outputs expose only selected internal resource attributes
- Root module shifts from direct ownership to module interface
- Resource addresses change when moved into a module
- Address changes cause Terraform to treat resources as new
- State migration aligns old and new resource identities
- Stable module interfaces reduce future refactor risk
Why this matters
Modules are not just folders.
They define ownership and control boundaries.
When a resource moves into a module,
its address shifts from root to module namespace.
That shift changes identity in Terraform state,
which can trigger unintended replacement if unmanaged.
Understanding module structure first,
and state behavior second,
prevents destructive refactoring mistakes.

