Maintaining Reusable Terraform modules in GitHub

Terraform | DevOps | GitHub | IaaC | Cloud

Arun Kumar Singh
6 min readOct 13, 2021

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 ofrootmodule 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 -

Terraform https://www.terraform.io/docs/language/modules/sources.html

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 main.tf, variables.tf, outputs.tf

  • Any inputs to your module should go into variables.tf
  • The output should go into outputs.tf
  • All resources should be in main.tf



Arun Kumar Singh

In quest of understanding How Systems Work !

Recommended from Medium


See more recommendations