"Utilize Terraform to set up a three-tier architecture on AWS."

Sumit MondalSumit Mondal
2 min read

What is 3-Tier Architecture?

Three-tier architecture is a software architecture pattern that divides an application into three interconnected layers: presentation, logic, and data. This design helps improve scalability, maintainability, and separation of concerns in software development.

Resources needed to be created are:-

  1. vpc.tf

  2. subnet.tf

    1. sg.tf

      1. route-tb.tf

        1. nat.tf

        2. internet-gw.tf

        3. variables.tf

        4. providers.tf

        5. ec2.tf

        6. alb.tf

        7. eip.tf

Resources we need to install in our Web-Servers and DB-Server are:-

  1. Install httpd in both the Web-Server:-

    sudo yum install httpd -y

    sudo systemctl start httpd -y

    systemctl status httpd

  2. Install mysql in DB-Server:-

    sudo yum install mysql -y

How to execute our Terraform scripts:-

  1. terraform init

  2. terraform validate

  3. terraform plan

  4. terraform apply

  5. terraform destroy - After your project is finished execute this command

After terraform apply then switch to our both Web-Server & DB-Server created by using Terraform:- ssh -i <keypair.pem> ec2-user@publicip_of_server-1 and Start our httpd service. Do the same with Server 2.

Then go to DB-Server:- ssh -i <keypair.pem> DB-Server_Private-IP and install mysql.

Final-Output:-

Finally, our complete 3-Tier Application is up and running with Application LoadBalancer

Tips:- While switching to Different servers change the pem file permissions every time to 400 e.g.:- chmod 400 keypair.pem

Terraform Installation Commands for Amazon-Linux:-

  1. sudo yum install -y yum-utils

  2. sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo

  3. sudo yum -y install terraform

  4. terraform -v

2
Subscribe to my newsletter

Read articles from Sumit Mondal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sumit Mondal
Sumit Mondal

Hello Hashnode Community! I'm Sumit Mondal, your friendly neighborhood DevOps Engineer on a mission to elevate the world of software development and operations! Join me on Hashnode, and let's code, deploy, and innovate our way to success! Together, we'll shape the future of DevOps one commit at a time. #DevOps #Automation #ContinuousDelivery #HashnodeHero