Terraform Modules: Composition Over Abstraction
Terraform makes it easy to build large, highly abstracted modules that try to solve everything in one place. At first glance, this feels efficient: fewer modules, fewer calls, less wiring.
In practice, that approach often creates more problems than it solves.
A better pattern-especially as infrastructure grows-is to design small, focused, “atomic” modules and combine them using composition .
What We Mean by Composition
In this context, composition means:
Building infrastructure by combining smaller, independent modules instead of hiding everything behind a single, all-in-one module.
Instead of:
one module doing everything internally
you have:
multiple modules wired together explicitly
module "role" { ... }
module "policy" { ... }
module "attachment" { role = module . role . name policy = module . policy .…