Table of Contents
Terraform Modules are a powerful feature that allows you to create reusable and shareable configurations in Terraform. A module is a collection of Terraform resources, data sources, variables, outputs, and other components that work together to create a specific set of infrastructure resources. Modules enable you to encapsulate and abstract away complex configurations, making it easier to manage and maintain your infrastructure as code.
-
Encapsulation: Modules help you organize and encapsulate your infrastructure code. You can create separate modules for different components of your infrastructure, such as networking, compute instances, databases, etc. This promotes a more modular and maintainable structure.
-
Reusability: Modules can be used across different Terraform configurations. Once you define a module, you can call it multiple times with different input variables to create similar infrastructure resources in various environments.
-
Input Variables: Modules can accept input variables, which act as parameters to customize the behavior of the module. Input variables allow you to make your modules flexible and reusable in different scenarios.
-
Output Values: Modules can define output values, which are used to expose certain attributes or information about the created resources. Output values allow you to retrieve and use data generated by the module in other parts of your Terraform configuration.
-
Composition: Modules can be composed together, allowing you to build more complex infrastructure by combining multiple modules. This promotes the concept of "building blocks," where smaller modules are combined to create more significant infrastructure solutions.
-
Versioning and Sharing: Modules can be versioned using version control systems like Git, allowing you to track changes and promote reusability across teams. You can also publish and share modules through the Terraform Registry for others to use.
├── .env.example
├── .gitignore
├── .pre-commit-config.yaml
├── LICENSE
├── Makefile
├── README.md
├── ansible
│ └── playbook.yml
├── main.tf
├── modules
│ ├── ec2
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── sg
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── subnet
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ └── vpc
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
├── provider.tf
└── variables.tf
cp .env.example .env
Init
make tf-init
Plan
make tf-plan
Apply
make tf-apply
Apply Ansible Configs
make ansible-apply
Destroy
make tf-destroy
Run the following
pre-commit install