Creating VPC with public and private subnet and provisioning of NAT gateway for private subnets using Terraform

Creating VPC with public and private subnet and provisioning of NAT gateway for private subnets using Terraform

!! Hello Connections !!

Welcome you all to my article which is based on TASK 4 of Hybrid Multi Cloud Computing .

Basically , TASK 4 is just an upgraded version of TASK 3 .As it includes the update of provisioning NAT gateway for private subnet connectivity to public world .

TASK DESCRIPTION : Perform TASK 4 with same use case of WordPress and mysql but with an additional feature to be added that is NAT Gateway to provide the internet access to instances running in the private subnet .

So, let us start our workflow journey for completion of the task .

In these task we are going to implement same use case using terraform code as we done in previous TASK 3 ,but in these task we have to provision one gateway which gives access to private subnet to connect to public internet world for any update purpose but nobody from public world cannot go inside .These gateway that we are provisioning for private subnet is called NAT gateway .

1)First we have to login through aws CLI using aws configure command .

No alt text provided for this image

2)We have to create one VPC for our entire networking setup of infrastructure . But before running our terraform code we have to initialize it for downloading necessary plugins using terraform init command .

#terraform init

No alt text provided for this image

By running terraform code using terraform apply VPC is created for our infrastructure .

#terraform apply

No alt text provided for this image

3)After creating VPC , we have to write terraform code for creating two types of subnets like public subnet for WordPress and private subnet for mysql database server .

No alt text provided for this image
No alt text provided for this image

4)Now for the connectivity of the subnets like to go in and go out we have to create one public facing gateway called internet gateway . By which outside clients can connect to our WordPress application .

No alt text provided for this image
No alt text provided for this image

5)For internet gateway we have to configure one routing table which provides ip range to DHCP internally and attaching these routing table to public subnet .

No alt text provided for this image
No alt text provided for this image

6)To permit outside connectivity and also to do SSH to WordPress instance we have to create one security group for WordPress instance in public subnet which allows SSH on port 22 , WordPress server on port 80 and ICMP . Also for mysql database instance we have to create one security group which allows only port 3306 of mysql database server and security group of WordPress instance for their internal connectivity.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

7)Now we have to create the WordPress and mysql instances using precreated AMI that has already WordPress and mysql set up ready .

No alt text provided for this image
No alt text provided for this image

8)Finally we do all the terraform code setup and successfully implemented also .We can see whole setup of WordPress and mysql using terraform state list command .

#terraform state list

No alt text provided for this image

9)By using public ip of which is auto assigned to WordPress instance we can access WordPress application running under fully secured own created network setup using terraform

No alt text provided for this image
No alt text provided for this image

10)Till these step the workflow is same as like TASK 3 .Now we have to create one instance in public subnet which has main provision of going inside the mysql instance in private subnet via SSH . These instance is known as Bastion_Host . But before creating bastion_host we have to create one security group for it for SSH . Another security group we have to create for mysql instance in private subnet which allows only Bastion_Host instance to go inside .

Security groups for Bastion_Host and for mysql which allows Bastion_Host login --->

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Creating Bastion_Host instance in public subnet -->

No alt text provided for this image

11)For creating NAT gateway we require one static ip which is Elastic IP . It is a public ip given to NAT gateway by using these IP our database instance in private subnet can go outside to public world .

No alt text provided for this image
No alt text provided for this image

12)Now , we have to create NAT gateway for mysql instance running in private subnet .

No alt text provided for this image
No alt text provided for this image

13)At last we create routing table for NAT gateway and attaching it to mysql instance .Now our mysql instance can go outside to internet .

No alt text provided for this image
No alt text provided for this image

14)By running one single terraform code entire setup of the task is created . It is nothing but we are creating Netoworking As A Service (NAAS) by using terraform .

#terraform state list

No alt text provided for this image

In these way finally I completed TASK 4 of Hybrid Multi Cloud Computing .

Special thanks to Mr .Vimal Daga for giving such amazing real use case based task which enhances my technical skills in the world of hybrid multi cloud computing .

To get these powerful terraform code please go through my github repo .I shared the github repo link in my post .

Thanking you all for visiting my article










Chaitanya Chougule

Senior DevOps Engineer @Deltek

4 年

Awesome ..

回复
Sanket Bendale

Associate Consultant at Capgemini

4 年

Awesome?

回复
Vishal Dhole

Full Stack Web Developer | Angular | Node.js | AWS | DevOps | Immediate Joiner

4 年

Good work...

回复

Nicely done

回复

要查看或添加评论,请登录

Onkar Naik的更多文章

社区洞察

其他会员也浏览了