description |
---|
Create Terraform Modules locally. In this repository, you will find a step-by-step guide on developing and using Terraform modules locally, ideal for environments where access to the Terraform Public Registry is restricted from organizational private networks. The guide covers everything from downloading modules from the Terraform Public Registry to creating and executing local modules in your own environment. |
- How to develop Terraform modules locally ?
- How to leverage and use open source Terraform Modules locally if we don't have access from our organization private networks to Terraform Public Registry ?
- Copy
terraform-manifests
from06-AWS-VPC\06-02-AWS-VPC-using-Terraform\terraform-manifests\v2-vpc-module-standardized
- Download the VPC module from Terraform Public Registry
- Create
modules
folder in Terraform Working Directoryterraform-manifests
- Copy the downloaded VPC module to
modules
folder with module folder nameaws-vpc
- Remove all other unused or un-required files from this downloaded module.
- Update the
source
argument inc4-02-vpc-module.tf
- Also comment
version
argument
# Create VPC Terraform Module
module "vpc" {
source = "./modules/aws-vpc"
#version = "2.78.0"
### BELOW Terraform code is truncated and will be available in c4-02-vpc-module.tf
# Terraform Initialize
terraform init
Observation:
1. Verify the cli output
2. Verify the .terraform\modules folder
3. It will just have the module.json file referencing to local modules folder where aws-vpc module is present
# Terraform Validate
terraform validate
# Terraform Plan
terraform plan
# Terraform Apply
terraform apply -auto-approve
- If we want to develop local modules in our organization, don't need to build everything from scratch
- Analyze what all open source modules available for us and use them and change those as per our requirement.
- If we don't relevant module, atleast refer these module related code
main.tf
to get how the advanced level code they write to build such type of re-usable modules
# Terraform Destroy
terraform destroy -auto-approve
# Delete Files
rm -rf .terraform*
rm -rf terraform.tfstate*