Creating web portal for a company with a secure VPC in AWS Cloud …

What we have to do :
1) Write a Infrastructure as code using terraform, which automatically create a VPC.
2) In that VPC we have to create 2 subnets:
a) public subnet [ Accessible for Public World! ]
b) 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) Launch an ec2 instance which has Wordpress setup already having the 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.
6) Launch an ec2 instance which has MySQL setup already with security group allowing port 3306 in private subnet so that our wordpress instance can connect with the same.Also attach the key with the same.

Note:
→Wordpress instance has to be part of public subnet so that our client can connect our site.
→MySQL instance has to be part of private subnet so that outside world can’t connect to it.
→Don’t forgot to add auto ip assign and auto dns name assignment option to be enabled.

Now coming to hands-on part with step by step …

Step 1: Configure the aws using the cmd : aws configure

Step 2: Now write the terraform code to create a secure VPC ….
→ Creating the VPC by giving cidr blocks as 192.168.0.0/16

ALong with VPC , we need to create Subnets / labs for that VPC …
So, keep in mind we have given CIDR Blocks as 192.168.0.0/16
We are going to create two subnets one is public and another one is private…
→ Public: It is access to entire world ..
→ Private: It is not access to world .. And its is internally connected to instances which are belongs to VPC which we have created above …
Here is the code …

Step 3: In the above , we have discussed that we are going to create one public subnet and one private subnet .. So, we have to give internet and all other access to public subnet to connect entire world …
For this, we have to create Internet Gateway in the VPC which we have created … And this gateway must be associated to our public subnet … To associate, we have to create a route table .. Here is the code …

Step 4: Create a security group which has to allow HTTP , SSH , and MySQL protocol …
→ HTTP : To allow port 80 … Wordpress is build on apache webserver …. So that we must allow HTTP protocol ..
→ SSH : We don’t require, But for further login purpose
→ MySQL : Which allows MySQL port 3306 …
Here is the code …

Step 5: It is last step … Now launch wordpress instance and MySQL instance … And also attach key for further login purpose … Attach the above security group .. Allow auto IP address to get public IP address whenever we launched the instance …
Note :
→ Wordpress Instance should be in public Subnet . So that, we can access from outer world ( Accessible for outer world )
→ MySQL Instance should be in private subnet. So that, outer world can’t access our Database ( Restricted from outer world )…
Here is the code …

Coding part is done …
Now run the terraform code which we have written …
command : terraform apply …
You can use --auto-approve also …

Outputs:
→ Terraform apply ..

→Step 2

→Step 3:

→Step 4:

→Step 5:

Wordpress sites :

Done with the task ….
Here is the code →
GitHub Link
Thanks for Reading ….

…. Signing off ….

Doing Intern at ARTH - School Of Technologies