Creating Amazon Virtual Private Cloud(VPC) using Public and Private Subnets for WordPress and MySQL database server using Terraform

Shreyas Basutkar
4 min readSep 20, 2020

--

Hello World! In this article, I am going to talk about an overview of Terraform and the creation of Virtual Private Cloud (VPC) and using public and Private Subnets for WordPress & MySql database using Terraform Tool.

So normally there are a few steps to perform this practical as follows:

  1. We have to configure our AWS profile :

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 the terraform init command.

#terraform init

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

#terraform apply

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 .

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.

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 .

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 .

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

8)Finally we do all the terraform code setup and successfully implemented. We can see our wordPress site is ready.

--

--