Menu

Terraform Modules: Composition Over Abstraction
📰

Terraform Modules: Composition Over Abstraction

DEV Community·Bartłomiej Danek·7 months ago
#VRsoOXAf
#terraform#create#more#terragrunt#modules
Reading 0:00
15s threshold

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 .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.