Terraform Modules explained!!!

A module is a container for multiple resources that are used together. Modules can be used to create lightweight abstractions, so that you can describe your infrastructure in terms of its architecture, rather than directly in terms of physical objects.

A Terraform module is very simple: any set of Terraform configuration files in a folder is a module.

Create a new folder called modules and move all the files (that is, main.tf, variables.tf, and outputs.tf) from the web server cluster into modules/services/webserver-cluster.

Open up the main.tf file in modules/services/webserver-cluster and remove the provider definition.

Providers should be configured by the user of the module and not by the module itself.

$ tree minimal-module/
.
├── README.md
├── main.tf
├── variables.tf
├── outputs.tf

Reference

  • https://github.com/KensoDev/terraform-example-with-modules
  • https://medium.com/@mitesh_shamra/module-in-terraform-920257136228
  • https://www.terraform.io/docs/modules/index.html
  • https://github.com/MiteshSharma/TerraformModules
  • https://github.com/devopsschool-sample-projects/TerraformModules
Rajesh Kumar
Total Page Visits: 497 - Today Page Visits: 1