This project demonstrates how to deploy a three-tier architecture on AWS using Terraform. A three tier architecture consisting of three layers: the web tier, the application tier, and the database tier. Each layer has a specific role and interacts with the other layers to form a scalable and resilient application, with components such as EC2 instances, RDS, Elastic Load Balancer (ELB), VPC, and ASG. This project uses Terraform modules to organize and manage the infrastructure code effectively, making it easily reusable.
- Web Tier: EC2 instances running in multiple Availability Zones, fronted by an Elastic Load Balancer.
- Application Tier: EC2 instances for application processing in a private subnets also load-balanced and running in multiple Availability Zones.
- Database Tier: An Amazon RDS instance running in a private subnets.
Before you begin, ensure you have:
- Basic knowledge of Terraform and AWS services such as EC2, ELB, ASG, RDS and VPC
- Terraform installed on your local machine
- An AWS account
- AWS CLI configured with appropriate IAM user credentials (secret access key and access key ID)
git clone https://github.com/theglad-x/Three-Tier-Architecture-Deployment-on-AWS-with-Terraform.git
cd Three-Tier-Architecture-Deployment-on-AWS-with-Terraform
Create S3 bucket for backend to store Terraform state file. The S3 bucket can be created with either
- The configuration in
./s3-bucket.tf
file - Through the AWS management console
Open in a text editor main.tf
file in the project root directory and configure your email for web tier and app tier ASG notification
In the project root directory, open terraform.tfvars
in a text editor
Review and customize the values of the variables according to your reguirement.
image_name
: Set the value for ami filtermy_public_key
: Set location of the public key for keypairdb_password
: Set the database passworddb_username
: Set username for the databaseip
: Set ip for the host machine
Run fmt command to fix any syntax error
terraform fmt
terraform init
Run the following command to see all resources terraform will create and check if matches your expection
terraform plan
terraform apply
After deployment is complete, the web application can be access via the Elastic Load Balancer's DNS name. Copy the DNS name Terraform will output and paste it into your web browser.
Login to AWS console to confirm all the resources created
This project uses Terraform modules to organize and manage the infrastructure code effectively. You can reuse these modules or customize them as needed.
This project demonstrates the power of Terraform in deploying a secure and scalable three-tier web application architecture on AWS. By leveraging Terraform modules and AWS services such as EC2, ELB, RDS, and ASG, this setup ensures high availability, fault tolerance, and ease of management. The modular nature of the code makes it reusable and adaptable to different requirements, allowing for customization and further expansion as needed.
With this setup, you can easily deploy, manage, and scale your infrastructure while maintaining best practices in cloud architecture. Ensure to follow Terraform's best practices for structuring configurations and AWS best practices. Secure sensitive data using Terraform's sensitive attribute and gitignore your .tfvars file