Terraform: avoid modules nobody dares to change
Reuse does not mean turning all infrastructure into one module with fifty variables.
Premature abstraction is expensive
A module built for every project accumulates flags, conditionals and confusing outputs. It is reusable in theory and risky to change in practice.
A structure that usually works
- Root modules by environment or system: compose resources and deployment decisions.
- Small modules: encapsulate repeated patterns with one responsibility.
- Pinned versions: prevent unreviewed shared changes.
- Plans in pull requests: expose impact before apply.
What should not become a variable
If an option breaks the security model or creates a different architecture, it likely deserves another module. Useful flexibility keeps contracts clear.
Refactor without stopping production
Stabilize providers, state and pipelines first. Then extract modules without recreating resources, using reviewable plans and small changes.
Sources reviewed
This article is an original Nubent synthesis. The sources let you inspect the basis and explore each subject further.