Creating a Public Subnet with Internet Gateway and NAT Gateway and a Private Subnet

TASK :

1. Write an Infrastructure as code using terraform, which automatically create a VPC.

2. In that VPC we have to create 2 subnets:

1. public subnet [ Accessible for Public World! ]

2. private subnet [ Restricted for Public World! ]

3. Create a public facing internet gateway for connect our VPC/Network to the internet world and attach this gateway to our VPC.

4. Create a routing table for Internet gateway so that instance can connect to outside world, update and associate it with public subnet.

5. Create a NAT gateway for connect our VPC/Network to the internet world and attach this gateway to our VPC in the public network

6. Update the routing table of the private subnet, so that to access the internet it uses the nat gateway created in the public subnet

7. Launch an ec2 instance which has Wordpress setup already having the security group allowing port 80 sothat our client can connect to our wordpress site. Also attach the key to instance for further login into it.

8. Launch an ec2 instance which has MYSQL setup already with security group allowing port 3306 in private subnet so that our wordpress vm can connect with the same. Also attach the key with the same.

The steps to perform the task are:

  1. Write an Infrastructure as code using terraform, which automatically creates a VPC.
“myvpc”

2. In that VPC we have to create 2 subnets:

1. public subnet [ Accessible for Public World! ]

2. private subnet [ Restricted for Public World! ]

“mysubnet1” and “mysubnet2”

3. Create a public facing internet gateway for connect our VPC to the internet world and attach this gateway to our VPC.

“mygw”

4. Now create a routing table for Internet gateway so that instance can connect to outside world, update and associate it with public subnet.

“myrt”

5. Make sure you make an Elastic ip for internet gateway.

“eip”

6. Create a NAT gateway for connect the VPC to the internet world and attach this gateway to VPC in the public network.

“natgw”

7. Update the routing table of the private subnet because for accessing the internet, it uses the NAT gateway created in the public subnet.

“natroute”

8. Launch an EC2 instance which has Wordpress setup already and security group allowing port 80 so that our client can connect to our wordpress site. Also attach the key to instance for further login into it.

“wpos”

9. Launch an EC2 instance which has Mysql setup already and security group allowing port 3306 in private subnet so that our wordpress vm can connect with it. Also attach the key with the same.

“mysqlos”

10. Launch bation host EC2 instance in the public subnet with a security group allowing port number 22 with a key attached to it.

“bationhost”

The wordpress site can be accessed.

Thanks for reading!

Linkedin — https://www.linkedin.com/pulse/creating-public-subnet-internet-gateway-nat-mitaali-dayal