Deploy a Three-Tier Architecture in AWS Using Terraform
When designing cloud-based applications, a three-tier architecture is a common and efficient approach. This architecture divides the application into three layers: the presentation layer, the business logic layer, and the data storage layer. In the context of Amazon Web Services (AWS), Terraform can help you automate and manage the deployment of such an architecture, providing a flexible and scalable solution.
In this guide, we’ll walk you through the process of setting up a Three-Tier Architecture in AWS using Terraform. By the end, you’ll have a fully operational infrastructure with VPC, subnets, EC2 instances, an RDS database, and more.

What is a Three-Tier Architecture?
A three-tier architecture splits an application into three separate layers:
- Presentation Layer: The user interface (UI), often a web application.
- Business Logic Layer: The backend server handling the application’s logic.
- Data Layer: The database that stores application data.
This separation ensures that each tier can be managed, scaled, and updated independently, enhancing security, performance, and maintenance.
AWS Services Used for Three-Tier Architecture
To deploy this architecture in AWS, we will leverage several AWS services:
- Elastic Compute Cloud (EC2): To host the application and web servers.
- Virtual Private Cloud (VPC): To create isolated network environments.
- Elastic Load Balancer (ELB): To distribute traffic across multiple EC2 instances.
- Security Groups: To manage network traffic and instance security.
- Internet Gateway: To enable internet access for public instances.
- RDS: To provide a scalable and managed database.
Introduction to Terraform
Terraform is a powerful Infrastructure-as-Code (IaC) tool that allows you to manage cloud infrastructure using code. With Terraform, you can define, deploy, and update infrastructure resources efficiently and reproducibly. It supports various cloud providers, including AWS.
Steps to Deploy a Three-Tier Architecture Using Terraform
Below is a breakdown of the steps involved in creating a Three-Tier Architecture in AWS using Terraform.
1. Set Up the AWS Provider for Three-Tier Architecture
Before we begin creating resources, we need to set up the AWS provider in Terraform to allow communication between Terraform and AWS. You’ll need your AWS credentials (access key and secret key).
provider "aws" {
access_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
region = "us-west-2"
}
2. Create the Virtual Private Cloud (VPC)
A VPC is a network isolated from other AWS customers. Let’s start by creating the VPC for our application.
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Name = "my_vpc"
}
}
3. Set Up the Internet Gateway
The Internet Gateway allows communication between instances in your VPC and the internet. We need to attach it to the VPC.
resource "aws_internet_gateway" "gateway" {
vpc_id = aws_vpc.main.id
}
4. Create Subnets
We need at least three subnets: one public and two private subnets. The public subnet will host the web servers, while the private subnets will host the database and other backend services.
resource "aws_subnet" "public" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.0.0/24"
availability_zone = "us-west-2a"
map_public_ip_on_launch = true
tags = {
Name = "public-subnet"
}
}
resource "aws_subnet" "private" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-west-2b"
tags = {
Name = "private-subnet"
}
}
5. Set Up NAT Gateway for Private Instances
Private instances need internet access to download updates or packages. A NAT Gateway in the public subnet allows private instances to access the internet without exposing them directly.
resource "aws_nat_gateway" "nat" {
allocation_id = aws_eip.nat.id
subnet_id = aws_subnet.public.id
}
6. Create the RDS Instance for Data Storage
Now, let’s set up an RDS instance to handle data storage. RDS is a managed database service that simplifies the process of setting up, operating, and scaling a database in the cloud.
resource "aws_db_instance" "db" {
identifier = "my-db"
engine = "mysql"
instance_class = "db.t2.micro"
allocated_storage = 20
username = "admin"
password = "mypassword"
db_name = "mydatabase"
vpc_security_group_ids = [aws_security_group.db.id]
}
7. Configure Security Groups
Security groups act as firewalls for your EC2 instances and other resources. Let’s define security rules for our web and database instances.
resource "aws_security_group" "web" {
vpc_id = aws_vpc.main.id
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
8. Deploy EC2 Instances for Web and Application Servers
You can use EC2 instances to host the web and application servers. The web servers will handle incoming traffic, while the application servers will process business logic.
resource "aws_instance" "web" {
ami = "ami-0b419c3a4b01d1859"
instance_type = "t2.micro"
subnet_id = aws_subnet.public.id
security_group_ids = [aws_security_group.web.id]
tags = {
Name = "web-server"
}
}
9. Finalize Deployment with Terraform
Once your Terraform code is ready, initialize the configuration, plan the deployment, and apply it.
terraform init
terraform plan
terraform apply
Terraform will provision the resources in AWS, creating your three-tier architecture with the configurations you’ve defined.
ZippyOPS Expertise in Cloud Infrastructure
At ZippyOPS, we specialize in cloud infrastructure design and deployment, offering expert consulting, implementation, and managed services. Whether you’re setting up DevOps, DevSecOps, or MLOps environments, our team ensures your systems are secure, scalable, and optimized for performance. We provide end-to-end solutions across areas like Microservices, Cloud, DataOps, AIOps, and more.
Learn more about our services: ZippyOPS Services
Check out our product offerings: ZippyOPS Products
Explore our cloud solutions: ZippyOPS Solutions
For more insights and a demonstration of our capabilities, visit our YouTube channel.
If you’d like to discuss your project, reach out to us at sales@zippyops.com.



