Deploying an Application using VPC,NAT Gateway and Internet Gateway
Our requirement is to create a web portal for our company with all the security.So,we need to use WordPress with dedicated DB Server.In our case,Database should be provided the Internet Connectivity and should be created in Private Subnet.Also,we need to public WordPress for our clients and should be created in Public Subnet
For performing this,we need-
1-AWS Account for using its services
Use this link to create AWS Account:- https://aws.amazon.com/
2-Terraform package for using terraform command
Use this link for downloading Terraform:- https://www.terraform.io/downloads.html
For this purpose,perform following tasks-
1-After downloading Terraform,provide the Path to it.
2-Select Environment Variables and then click to Path and write the Path of terraform in it.
3-Now,check by typing terraform version in command prompt.
4-Now,we have to create a Terraform Code for performing our task.First,we have to specify AWS as a provider.
5-Now,we will create a VPC
6-Now,we will create 2 subnets ie. first one will be public(for WordPress) and the other one will be private(for MYSQL)
7-Now,we will create an Internet Gateway to connect our VPC to the outside world ie. Internet
8-Now,create a routing table for Internet Gateway so that instance can connect to outside world.
9-Now,associate Internet Gateway with public subnet
10-Now,create a NAT Gateway and provide it with Internet Connectivity along with its Elastic IP
11-Now,create a routing table for NAT Gateway and associate it with private subnet
12-Now,create key pair for WordPress and MYSQL ie, public and private
13-Now,create Security Group for WordPress
14-Now,create Security Group for MYSQL
15-Launch the WordPress instance using the above security group
16-Launch the MYSQL instance using the above security group
17-Now,just print the Public IP of WordPress instance on command prompt
18-Now,type following commands in command prompt-
terraform init #Downloads AWS plugins internally
terraform validate #Validates the terraform code
terraform plan #Displays the resources which will be created by our code
terraform apply -auto-approve
Thats's All!!
Our whole infrastructure is launched in AWS Cloud.We can see the resources running in AWS Console
Now,if we type the Public IP of WordPress in our browser-