- Core concepts and benefits
- How modules are composed and consumed
- Typical module file layout and usage examples
- Links and next steps for publishing and versioning modules
What are modules?
A Terraform module is a container for a set of resources that are commonly used together — for example, a VPC with subnets and route tables, a load balancer with its SSL configuration, or everything needed for a database tier. Modules let you encapsulate implementation details and expose only the inputs and outputs consumers need. You’ve already been using the root module (the configuration in your working directory). Modules simply let the root (or other parent modules) call child modules so that you can reuse and compose functionality across multiple stacks and teams.Benefits of using modules

Module composition and reuse
Instead of defining every resource for each application directly in the root module, extract common functionality into dedicated modules — for example: TLS certificate, load balancer, message queue, Kubernetes cluster, database. Then reference the modules you need from each root module. A module is called with amodule block. Example:
What does a module look like?
A module directory contains the same types of Terraform files you use in the root module. A typical, minimal module layout:
This pattern mirrors what you already use in your root module — modules are simply a re-packaging of that configuration into reusable units.

The root module is the configuration in your current working directory. When the root uses
module blocks it creates child module instances. Each child module is retrieved from a source (local folder, the Terraform Registry, a VCS repo, or an archived release) and exposes inputs/outputs defined in its variables.tf and outputs.tf.Next steps — best practices & resources
Focus next on:- Module inputs/outputs: design stable, minimal interfaces for consumers.
- Versioning: publish module releases and pin the
sourcewith a version constraint. - Documentation: include examples and clear variable/output descriptions in the module README.
- Testing: use tools like
terraform validate,tflint, and automated CI to validate module behavior before publishing.