Deploying AWS 2-Tier Architecture with Terraform

Manminder Singh
2 min readSep 5, 2022

Overview: We aim to make a 2-tier architecture in AWS with the following requirements using Terraform, which is an IAC tool.

1. Deploy a VPC with CIDR 10.0.0.0/16 with 2 public subnets with CIDR 10.0.1.0/24 and 10.0.2.0/24. Each public subnet should be in a different AZ for high availability.
2. Create 2 private subnets with CIDR ‘10.0.3.0/24’ and ‘10.0.4.0/24’ with an RDS MySQL instance (micro) in one of the subnets. Each private subnet should be in a different AZ.
3. A load balancer that will direct traffic to the public subnets.
4. Deploy 1 EC2 t2.micro instance in each public subnet.

Technology Used: AWS, Terraform CLI, Terraform,

The basic outline of 2 Tier Architecture of the AWS resources for this project

Above is the architecture behind the scenes to get deployed by the code below written in Terraform. We have created all the components in the main.tf file itself.

Once done with the main.tf file, run the below commands

terraform fmt          
# this formats the main.tf file used to rewrite Terraform configuration files to a canonical format and style
terraform init
# initialize a working directory containing
terraform plan
#The terraform plan command evaluates a Terraform configuration to determine the desired state of all the resources it declares, then compares that desired state to the real infrastructure objects being managed with the current working directory and workspace
terraform apply
#performs a plan just like terraform plan does, but then actually carries out the planned changes to each resource using the relevant infrastructure provider's API
terraform destroy
# this command is a convenient way to destroy the architecture.

--

--