Skip to content

Deploy Two-Tier Architecture on AWS using Terraform

Published: (4 min read)  at 06:46 AM

Project Introduction

In the world of cloud computing, infrastructure as code (IaC) plays a pivotal role in automating the deployment and management of resources. This blog post provides a step-by-step guide on creating a Two-Tier architecture on AWS using Terraform. We’ll explore the essential services involved, ensuring high availability, security, and scalability for hosting a static website.

Also, we are adopting a modular approach with enhanced security measures. The infrastructure is organized into dedicated modules, ensuring a scalable, maintainable, and secure deployment.

Directory Overview

Directory Overview

This modular approach enhances the project’s maintainability, making it easier to manage and scale as your infrastructure requirements evolve. Each module focuses on a specific aspect of the infrastructure, promoting reusability and clarity in configuration.

Pre-requisites

Before diving into the infrastructure creation, make sure you have the following:

Step-by-Step Guide

To get started, clone the repository using the following command:

git clone https://github.com/NotHarshhaa/DevOps-Projects

Navigate to the project folder:

cd DevOps-Projects/DevOps Project-11

Planning and Deployment

Execute the following Terraform commands to plan and deploy the infrastructure:

terraform plan -var-file=variables.tfvars
terraform apply -var-file=variables.tfvars --auto-approve

Once the deployment is complete, you can inspect the created services using the provided snippets for each service.

VPC

Public and Private Subnets

Public and Private Route tables

Internet Gateway

Elastic IP addresses

NAT Gateways

Security Groups

EC2 & AutoScaling Group

Launch template

AutoScaling Group

Target Group & Load Balancer

Target Group

Load balancer

Database

Subnet Group for RDS

RDS Cluster

After Core Service, Deploy Service on Server

Route53

AWS Certificate Manager

AWS Web Application Firewall

CloudFront

IAM Role

IAM Policy

IAM instance profile

TF State file and State lock

Backend- TF State file stored on S3

TF State lock file

Once the deployment is completed, you can enter your domain name in the browser to validate whether your servers are perfectly running or not.

As you can see in the below snippet, the Application is running

Clean-up

When you’re done exploring the Two-Tier architecture and want to avoid incurring unnecessary costs, follow these steps to clean up the resources:

Run the following command to initiate the destruction of the infrastructure.

terraform destroy -var-file=variables.tfvars --auto-approve

Delete the Repository (Optional):

rm -rf DevOps-Projects

This step is optional and depends on whether you plan to reuse the repository for future exploration.

By following these clean-up steps, you ensure that AWS resources are properly decommissioned, and you won’t incur unnecessary charges. Always exercise caution when performing destructive actions like terraform destroy to avoid unintended consequences.

Conclusion

In this comprehensive guide, we embarked on a journey to deploy a Two-Tier architecture on AWS using Terraform. Embracing a modular approach with enhanced security measures, our infrastructure is organized into dedicated modules, offering scalability, maintainability, and robust security.

Happy coding!

Feel free to reach out to me if you have any doubts or queries.

LinkedIn- https://www.linkedin.com/in/harshhaa-vardhan-reddy/

GitHub- https://github.com/NotHarshhaa/

Happy Learning!

Harshhaa Vardhan Reddy - DevOps Engineer / Blogger