Interview Prep/Terraform/Modules and Code Structure

When do you turn a block of resources into a module, and when do you leave it alone?

BeginnerScenarioModules and Code Structure
Answer

Situation read → Modules add indirection; they should earn their keep.

What I'd do →

  1. Create a module when the same pattern is used in 2–3 places, or when a team needs a safe, opinionated way to build something (VPC, ECS service, RDS).
  2. Keep one-off resources in the root module.
  3. Give the module a small, typed interface and meaningful outputs.

Why → A module with 40 pass-through variables is just a worse version of the resource. A good module hides complexity and enforces standards.

Interview tip → "A module should model a concept, not wrap a single resource."

All Terraform questions Roadmap: Terraform

More on Modules and Code Structure