"Utilize Terraform to set up a three-tier architecture on AWS."
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:-
vpc.tf
subnet.tf
sg.tf
route-tb.tf
nat.tf
internet-gw.tf
variables.tf
providers.tf
ec2.tf
alb.tf
eip.tf
Resources we need to install in our Web-Servers and DB-Server are:-
Install httpd in both the Web-Server:-
sudo yum install httpd -y
sudo systemctl start httpd -y
systemctl status httpd
Install mysql in DB-Server:-
sudo yum install mysql -y
How to execute our Terraform scripts:-
terraform init
terraform validate
terraform plan
terraform apply
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:-
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform
terraform -v
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