Before we can attach the internet gateway and public subnet to the VPC , we need to create the VPC(VIRTUAL PRIVATE CLOUD ) modules.
Here is an example of a vpc modules,
this particular module will creates a Virtual Private Cloud (VPC) resource in AWS. The "vpc_cidr_block" is the IP address range that the VPC will use, and "vpc_name" is a name that will be assigned to the VPC as a tag. The "aws_vpc" resource block is where the VPC will actually be created.
next we need to create an internet gateway modules and here is an examples of an internet gateway modules,
This Terraform module creates an Internet Gateway resource in AWS. In this module, the aws_internet_gateway resource is created, and it is associated with a VPC specified by the vpc_id attribute.
Remember internet gateway allow communication between instances in your VPC and the internet, so to associate your internet gateway to your vpc , you always need the vpc_id in your internet gateway modules. Overall, this module creates an Internet Gateway resource and associates it with a VPC, which is necessary for enabling internet access to resources in the VPC.
Next we need to create a public subnet, we can also have a private subnet which will be my next post with route tables but we are creating public subnet in this lecture and here is an example
Before explanation, what is subnet? A subnet, short for "subnetwork," is a portion of a larger network that has been divided into smaller, more manageable sections. In this case, the subnet is created in a public VPC, which means that it has access to the internet via an internet gateway.
The aws_subnet resource is used to create the subnet. It requires the VPC ID (which is specified in a separate resource called aws_vpc.main), the CIDR block (which is specified in a variable called var.public_subnet_cidr_block), and the availability zone (which is specified in a variable called var.availability_zones[0]). The tags block is used to assign a name to the subnet for easier identification.
Overall, this module is a simple way to create a public subnet in an AWS VPC, which can be useful for hosting public-facing resources like web servers or load balancers.
Top comments (0)