What is Terraform Module?
Terraform Modules are the reusable blueprints of your infrastructure. By building modules you can logically break down the infrastructure components and wrap those logical parts into re-usable chunks of IaC.
Basically, any set of standard Terraform configuration files in a folder is a Terraform module. You can reuse these modules and version them. The standard
.tf files which we write can directly deploy the infrastructure by executing
terraform init — >
terraform plan — >
terraform apply command. This is an example of
rootmodule defined in the main working directory. Every terraform module can call other
child modulesto include their resources in the configuration. Please note that Child modules can be called multiple times within the same configuration. Terraform Modules can be published in
Public or Private registries. The Terraform Registry hosts a number of
community or enterprise build publicly available Terraform modules for configuring many kinds of common infrastructure components. Apart from Registry, you can refer to modules from a number of different source types as well.
Following types of sources are currently supported in Terraform -
Following image is an example of importing a module from file system ,git and terraform registry.
How to create a Module?
Typical Modules folder structure involves three important files
- Any inputs to your module should go into
- The output should go into
- All resources should be in