Shashank jain
4 min readJul 15, 2020

--

VPC CREATION USING TERRAFORM

Today we are going to create our own vpc using terraform

we will do the mentioned task-

Statement: We have to create a web portal for our company with all the security as much as possible.

So, we use Wordpress software with dedicated database server.

Database should not be accessible from the outside world for security purposes.

We only need to public the WordPress to clients.

So here are the steps for proper understanding!

Steps:

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 vm 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.

1.so first we login with aws profile

2.than we will make a folder and initialize terraform

3.provider’s information

4.creating vpc

5.creating subnet

6.creating internet gateway and routing table

7.attaching routing table with subnet 1-

8.creating security group

9.creating instances

10.on cmd use terraform apply

Finally all resources are created(here you may see only teo resources but actually i applied command after some correction in my code so thats why )

BUT THE CODE IS ALL SET NOW YOU CAN USE IT DIRECTLY!!!

11.screenshots of resources created

12.now here wordpress pod is accessible by outside world

#thanks to mr.vimal daga sir

you can get full code by visiting my github account.

--

--