Understanding basics of Terraform #4- Terraform module

Understanding basics of Terraform #4- Terraform module

Terraform was initially released by hashicorp in 2014. One of the major reasons for release of Terraform is to reduce the use of Saas cloud provider manually.

Back in time, on premises is used to build cooperate network infrastructure. This means everything needed for cloud was installed locally. After a while, everyone moved to the cloud using cloud base providers such as AWS, gcp, azure, Linode, and digital ocean. This makes everything much faster, efficient, and practical.

Terraform came in by making things easy, instead of using your console manually to set up infrastructure. You can set up your infrastructure using terraform code. You can update your code if anything needs to changed.

Interesting thing about terraform is that the engineers good money, it is backed by masses.

Terraform Module

In terraform Module, you do not need to repeat yourself. You do not need to write another code. Terraform module is used to simplify terraform configuration. One of the interesting things about this module is the ability to share your infrastructure code with organizations, communities, and fellow developers.

Structures in Terraform Module

The major structures in Terraform Module are below

  1. Readme.md

  2. License

  3. Main.tf

  4. Variable.tf

  5. .tfvars

  6. Output

And many more structures from terraform registry.

License file makes you know under which it is being made available.

Readme contains the documentation that gives you insight on how to use the module.

Main.tf contains the main configuration. It is the first file that terraform looks for when trying to initialize the module from the backend.

Variable.tf is an argument file for required values. Variable file contains some argument that is not hard coded in the main.tf file.

.tfvars are set of arguments available in module block configuration.

Output.tf file contains the output of the configuration for a module folder.

However, you must be aware of some files that get created themselves the moment you initialize terraform after writing your code. These files are

  1. Terraform.tfstate: this shows the state of the terraform module.

  2. Terraform.tfstate.backup: this shows how terraform keeps track of the relationship between your configuration and infrastructure produced by it

  3. .terraform: this contains the module plugins used for the infrastructure provisioning.