Modules for Terraforms
Terraform modules are reusable packages of configuration that group resources behind input variables and outputs. A root module calls child modules from a local path, a Git repository or the Terraform Registry. Providers, such as the AWS provider, are plugins that implement the resources, and their versions are pinned. Modules and providers let teams build infrastructure from tested components.
Stage: Modules and Reuse · Part of the Terraform roadmap · Last reviewed 19 November 2026
What to learn in Modules
- Write a module with clear variables, outputs and a README
- Call a registry module and pin its version
- Pin provider versions in required_providers and commit the lock file
- Configure multiple provider instances with aliases for regions or accounts
- Decide when a module is worth creating and when it adds needless abstraction
Modules interview questions
Why pin provider and module versions?
Unpinned versions can change between runs, so a plan that worked yesterday might behave differently today after a breaking release. Version constraints and the .terraform.lock.hcl file make runs reproducible and let you upgrade deliberately after reading changelogs.
What makes a good Terraform module?
A good module does one coherent job, exposes a small set of well-named variables with sensible defaults and validation, outputs what callers need, avoids hard-coded environment values and is documented and versioned. Over-generic modules with many options are hard to maintain.
Where Modules fits in the Terraform roadmap
Modules belongs to the Modules and Reuse stage (intermediate level), which takes about 12 hours. Scale up.
Other units in this stage
Back to the full Terraform roadmap