Terraform modules registry
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed terraform modules.
https://cloudaffaire.com/terraform-modules/
In this blog post, we will discuss terraform modules registry and will use terraform community-supported modules to create a vpc. Terraform has a enrich community that provides free modules for the general public. Instead of creating your own module from scratch, you can use these modules to deploy your infrastructure.
You can download terraform community supported modules for aws using below GitHub repository.
https://github.com/terraform-aws-modules
Prerequisite for this demo:
- AWS account with proper access
- Terraform and Git
Next, we are going to create a vpc using community supported terraform modules.
Terraform community modules:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
##-------------------------------- ## Terraform: Module Registry ## ##-------------------------------- ## Create a directory name terraform and get inside it mkdir terraform && cd terraform ## Create a directory name module and get inside it mkdir module && cd module ## Clone the community supported vpc module from GitHub ## Complete list of modules: https://github.com/terraform-aws-modules ## git needs to be installed: https://cloudaffaire.com/how-to-install-git-in-aws-ec2-instance/ git clone https://github.com/terraform-aws-modules/terraform-aws-vpc.git ## Go to parent directory cd /home/ec2-user/terraform ## Create main.tf under terraform directory vi main.tf ----------------------- #Creates a VPC and subnets provider "aws" { access_key = " secret_key = " region = "ap-south-1" } module "vpc" { source = "./module/terraform-aws-vpc/" name = "myapp" cidr = "10.0.0.0/16" azs = ["ap-south-1a", "ap-south-1b"] private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] public_subnets = ["10.0.3.0/24", "10.0.4.0/24"] tags = { Owner = "debjeet" Environment = "test" } vpc_tags = { Name = "myvpc" } } ----------------------- :wq ## Create outputs.tf under terraform directory vi outputs.tf ----------------------- #generate output output "vpc_id" { description = "The ID of the VPC" value = "${module.vpc.vpc_id}" } output "private_subnets" { description = "List of IDs of private subnets" value = ["${module.vpc.private_subnets}"] } output "public_subnets" { description = "List of IDs of public subnets" value = ["${module.vpc.public_subnets}"] } ----------------------- :wq ## Format the code terraform fmt ## Initialize the provider terraform init ## Plan the changes terraform plan ## Apply the changes terraform apply ## Show state details terraform show ## Cleanup ## Destory resources terraform destory ## Remove terraform directory cd .. && rm -rf terraform |
Hope you have enjoyed this article. In the next blog post, we will discuss terraform functions.
For other modules provider, please refer below terraform registry.
https://registry.terraform.io/
To get more details on terraform, please refer below terraform documentation.
https://www.terraform.io/docs/index.html