You are currently viewing Terraform Modules

Terraform Modules

Terraform modules

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed how to deploy an AWS LAMP stack using terraform.

https://cloudaffaire.com/how-to-deploy-a-lamp-stack-in-aws-using-terraform/

In this blog post, we will discuss modules in terraform.

What are modules in terraform?

A module is a container for multiple resources that are used together. Every Terraform configuration has at least one module, known as its root module, which consists of the resources defined in the .tf files in the main working directory.

A module can call other modules, which lets you include the child module’s resources into the configuration in a concise way. Modules can also be called multiple times, either within the same configuration or in separate configurations, allowing resource configurations to be packaged and re-used.

Modules can be called by calling the module block

The resources defined in a module are encapsulated, so the calling module cannot access their attributes directly. However, the child module can declare output values to selectively export certain values to be accessed by the calling module.

Next, we are going to create a vpc and a subnet using terraform module concept.

Below is the directory structure for this demo.

We have main block in the root level and two directories for vpc and subnet. Each directory (module) has its own main block. Modules are called in the root level main block using module block.

Terraform modules:

Hope you have enjoyed this article. In the next blog post, we will continue with terraform module and will use the community supported modules to create a vpc.

To get more details on terraform, please refer below terraform documentation

https://www.terraform.io/docs/index.html