Using Terraform to Deploy EC2, VPC w/Public and Private Subnets, Aurora RDS Mysql instance and Load Balancer

Eric Wainwright
3 min readMay 31, 2022
Terraform, EC2, Aurora RDS Mysql Instance, VPC, Subnetting & Load Balancer

In this publication I will be completing the following tasks:

  1. Deploy a VPC w/ CIDR w/ 2 public subnets w/ CIDRs or and
  2. Create a private subnet w/ CIDR w/ an RDS MySQL instance (nano).
  3. A Load Balancer that will direct traffic to the public subnet.

You will need the following to complete these tasks:

  • AWS Account
  • Terraform installed
  • Fork my Github repo —
  • After forking repo you will have access to my code with the following files being created;, and .

To start my project I first had to create a working directory to setup all the files mentioned above.

Pictured above is my directory tree with all files listed.

You can use any IDE of your choice in my case I am using Cloud9. The first file I will create inside of the directory called “Terraform”; and it can be viewed below.

The provider is configured as AWS the region its being launched in is us-east-1.

Above the Terraform Amazon Web Services (AWS) provider is a necessary file to interact with the many resources supported by AWS. You must configure the provider with the proper credentials before you can use it.

Next, I will create the file shown in the directory tree above called,

Variables in Terraform are used to define centrally controlled reusable values. The information in Terraform variables is saved independently from the deployment plans, which makes the values easy to read and edit from a single file. And there are two different types of variables input/output.

The last file I will create is the file which is holding the resource code. And it appears as follows below.

Resources are the most important element in the Terraform language. Each resource block describes one or more infrastructure objects, such as virtual networks, compute instances, or higher-level components such as DNS records. Resource Blocks documents the syntax for declaring resources.

Now that we have all the code created in individual files I will initiate the Terraform init command to start up terraform.

Terraform successfully initialized above.

Next, we will run a terraform apply to see the IaC that will be constructed. You will notice that Terraform will not build anything until I provided my AWS credentials Username and Password.

After applying AWS credentials Terraform IaC is constructed
As seen above the Terraform apply was run successfully with 7 resources to be added.

The build was successful using Terraform IaC as shown with the terraform show command above. Below you will see the results of IaC as it has built my environment consisting of EC2, VPC, IGW, w/both Public and Private Subnets, as well as, an Aurora RDS instance and a (ALB) or Application Load Balancer.

Above is the results of the Iac I have constructed using Terraform.

Terraform is user friendly tool that will make your efforts of building IaC a little less cumbersome. So, do not be afraid to pick Terraform and play around it can be a lot of fun.



Eric Wainwright

DevOps engineer in search of Cloud Engineer role. Looking for Cloud Operations or Cloud Infrastructure opportunities.