https://www.youtube.com/watch?v=GdyhT7FC-QA
This project is focussing on automating the creation of a three tier architecutre on AWS using the Infrastructure as a code tool "Terraform".
This project focuses on automating the deployment of a scalable three-tier architecture on AWS using Terraform, an Infrastructure as Code tool.
- Autoscaling Group: Scales the front-end component for robustness.
- Bastion Host: Facilitates secure access to application tier instances in a private subnet.
- NAT Gateway: Enables outbound internet traffic from private subnets.
- Backend Logic and APIs: Provides functionality to the web tier.
- Internet-Facing Load Balancer: Directs incoming traffic to application instances.
- AWS RDS MySQL: Managed relational database service for data storage.
- Virtual Private Cloud (VPC) with multiple subnets (public, private, database).
- Internet Gateway: Provides internet access to the VPC.
- Route Tables and Security Groups: Manage traffic routing and network security.
- AWS RDS Instance: MySQL database instance for persistent data storage.
- Application Load Balancer: Distributes incoming application traffic across multiple targets.
- Autoscaling Group: Scales EC2 instances based on traffic demands.
- Launch Templates: Defines the configuration of EC2 instances.
To avoid state file conflicts when multiple teams are working, a remote backend is configured.
I have created a MERN stack application to have an interface for managing the infrastructure. Components used for the front-end
- React
- Clerk (for Authentication)
Components used for the backend
- Node & Express
- MongoDB
- NGROK for endpoint
1.Create a .env.local file in client folder with the following:
VITE_CLERK_PUBLISHABLE_KEY= your-clerk-key
Start the application
cd client
npm i
npm run dev
- Create another env file for backebd
CLERK_WEBHOOK_SECRET=
JENKINS_USERNAME=
JENKINS_TOKEN=
APITOKEN=
ENCRYPTION_KEY=32byterandomencryptionkey
ALGO=aes-256-cbc
Start the application
cd server
npm i
nodemon server.js
- Create an endpoint using ngrok, and start it at port 3000 Example: ngrok http --domain=yourapp.ngrok-free.app 3000
ngrok is used to provide an endpoint for API so that user details can be stored in database directly from clerk. The other use is that it is used to call APIs from jenkins.
You need to use the below commands to access the infrastrcture
# Download the key from Signed URL link provided.
# To set permissions.
chmod 400 "project-key.pem"
# Copying the key to the bastion host, find the IP of the bastion host from the aws console.
scp -i project-key.pem project-key.pem [email protected]:/home/ubuntu/
# Connect to the bastion host
ssh -i "project-key.pem" [email protected]
#Connect to instances in private subnet, again find the private IP from the AWS Console.
ssh -i "project-key.pem" [email protected]
# Command to connect to mysql instance
mysql -h projectdb.cr2mgycg0xoo.ap-south-1.rds.amazonaws.com:3306 -P 3306 -u root -p
- Clone Repository:
git clone https://github.com/akshatmiglani/Terraform-Learning.git
- Change Directory:
cd <project-directory>
- Configure AWS CLI:
- Create a new IAM User with necessary permissions.
- Configure AWS CLI with access key and secret access key:
aws configure
-
Create S3 Bucket for Remote Backend:
- Enable versioning for the S3 bucket (mandatory).
- Update details in backend.tf file
-
Modify tfvars File:
- Configure Database username, password, and Amazon AMIs for launch template.
-
Initialize Terraform:
terraform init
- Apply Terraform Configuration:
terraform apply
-
View Infrastructure on AWS: Check your AWS account dashboard to view the deployed infrastructure. View the S3 bucket to view the state file.
-
Access Application: Copy the DNS name provided by the Application Load Balancer into your browser to access the application.
-
Destroy Infrastructure:
terraform destroy