Interview Prep/Terraform/Modules and Code Structure

You inherit a module nested five levels deep and nobody can follow it. What do you do?

AdvancedScenarioModules and Code Structure
Answer

Situation read → Over-abstraction.

What I'd do →

  1. Map the real resources with terraform state list and terraform graph.
  2. Flatten to at most two levels: root calling modules calling resources.
  3. Use moved blocks while collapsing wrappers so state stays untouched.
  4. Verify with terraform plan showing no changes.

Why → Deep wrappers pass variables through layers without adding value, and every layer is another place for a bug.

Interview tip → Refactor behind a no-diff plan; that's your safety net.

All Terraform questions Roadmap: Terraform

More on Modules and Code Structure