Terraform
Modules overview
A module is a collection of resources that Terraform manages together. This page provides an overview of module concepts and phases for adopting modules. For information about creating and distributing modules, refer to Develop modules.
Introduction
When you repeatedly provision collections of resources with similar configuration, such as networking resources for new development environments, you should write reusable modules to codify them. Modularizing and sharing configurations helps you standardize how you provision infrastructure and lets you quickly and predictably provision the resources you need.
Hierarchy
Every Terraform workspace includes configuration files in its root directory. Terraform refers to this configuration as the root module.
Modules you configure using module
blocks are called child modules. When you apply a configuration, the root module calls the child module. As a result, Terraform adds the child module's resources to your workspace and manages them as part of the configuration.
You can configure the root module to call child modules multiple times within the same configuration. The root module can also call a child module that calls its own nested child module.
Sources
Terraform can load modules from multiple sources, including the local file system, a Terraform registry, and VCS repositories.
The public Terraform registry hosts a broad collection of publicly-available Terraform modules for configuring many kinds of common infrastructure. Modules on the public registry are created and maintained by HashiCorp, our partners, and the Terraform community. They are free to use and Terraform can download them automatically if you specify the appropriate source and version in a module
block.
Members of your organization may create modules specific to your infrastructure needs. HCP Terraform and Terraform Enterprise include a private module registry for sharing modules internally within your organization.
Workflows
The following phases describe the module implementation workflow:
- Develop: Module developers collect resource configurations into a module. Modules follow a standard structure and should include documentation. Refer to Develop modules for more information.
- Distribute : Terraform lets users access modules from several kinds of sources, including S3 buckets and GitHub repositories. The most common method is to publish your module to the public Terraform registry or to a private registry. Refer to Publishing modules for more information.
- Provision: Module consumers can use the
module
block in their configurations to call modules published to one of the supported kinds of sources. Refer to use modules in your configuration for more information.