Creating VPC using Terraform

Mohit Verma
4 min readJul 12, 2020

Creating a VPC with Private and Public subnets. Also creating instance with wordpress and another instance with MySQL. MySQL Instance can be only accesed by wordpress instance only. Sql Instance cannot be connected from any other public ip.

Task

Using Terraform create:

  1. VPC

2. Private Subnet

3: Public Subnet

4. Internet Gateway

5. Route Table

6. Security Group for WordPress Instance

7. Security Group for MySQL Instance

8. WordPress EC2 instance inside our public subnet with an associated security group and a generated key pair

9. MYSQL EC2 instance inside our private subnet with an associated security group and a generated key pair.

10. Show all terraform steps

Lets Start:

Step 1: Configuring Cloud Provider, Profile, Region

Step 2: Configuring CIDR

Step 3: Creating VPC

Step 4: Creating Public Subnet

Step 5: Creating Private Subnet

Step 6: Creating Internet Gateway associated with VPC

Step 7: Creating Route Table in VPC

Route table that directs internet-bound traffic to the internet gateway

Step 8: Creating Security group for WordPress Instance

Only allow port 22 for SSH and port 80 for http

Step 9: Creating Security group for MYSQLInstance

Only allow port 3306

Step 10: Launching WordPress instance with our Public Subnet

Step 11: Launching MYSQL instance with our Private Subnet

And DONE!!

Step12: Launching the Environment

Use following command to launch Environment

Step 13: Lanching your Wordpress Website

To launch Wordpress Deployment use ip address of wordpress instance

Step14: Destroying the whole Environment

Thanks

All suggestions are welcome to make the article and code better.

GITHUB REPO :

Below you can find the complete code -

Connect with me on LinkedIn:

--

--

Mohit Verma
0 Followers

Hybrid Multi CLoud | Amazon EKS | Flutter