Terraform - Module

Welcome to the blog! day 5 Today, we're diving into the world of Terraform and how it becomes tricky when many developers are working on the same project. Picture this: lots of changes happening at once, all affecting the same project's state file. It can be a recipe for conflicts and chaos in your infrastructure. But fear not! We're here to introduce you to a superhero solution called remote state locking.
In the series of Terraweek moving forward with more deep concepts.
Task 1:
1. What are modules in Terraform and why do we need modules in Terraform? What are the benefits of using modules in Terraform?
The module is another directory that contains .tf files. It helps to make code reusable. Modules can be remote or local.
In essence, modules in Terraform make it easier to manage and scale your infrastructure as code by promoting code reuse, reducing complexity, and enhancing collaboration among team members.
Task 2:
While creating the module we created the new dir ec2-repeat and created the module as modules.tf

Now we have configured the ec2 instance configuration in the ec2-repeat directory and provided the path to the module main.tf where we have configured the module.

cd /home/ubuntu/ec2.modules/ec2-repeat

In the above screenshot, we have mentioned the source path of the modules. Also, we have provided variables to modules.tf using var.tf
Now dir should be initialized as we have ad the module block.
terraform init
terrform plan


We can see the module is getting applied. now we create the multiple instances using 1 module block.
Task 3:
Dig into modular composition and module versioning.
Module Composition :
Module composition in Terraform refers to the practice of combining or nesting multiple modules together to create more complex infrastructure configurations. This allows you to build larger and more intricate infrastructure by reusing smaller, self-contained modules.

You can compose these modules to create a full application stack
We call this flat style of module usage module composition because it takes multiple composable building-block modules and assembles them together to produce a larger system. Instead of a module embedding its dependencies, creating and managing its copy, the module receives its dependencies from the root module, which can therefore connect the same modules in different ways to produce different results.
module versioning :
Module versioning in Terraform refers to the practice of assigning specific versions to your Terraform modules to ensure consistent and predictable infrastructure deployments.
It helps you manage changes to modules over time and maintain stability in your infrastructure.
Especially when you are working on UAT and PRODUCTION environment.
As soon as you make the changes in the directory it will impact both environments.
thank you for being here
If you've enjoyed this article and want to stay updated on the latest in the tech world, don't forget to connect with me on GOURAV TOONWAL. Let's keep the conversation going and explore the exciting world of technology together. Follow for more insights, discussions, and tech updates.
spreading knowledge in the community ...


