Skip to content

Commit b204b78

Browse files
Merge pull request #1 from NotHarshhaa/master
DevOps: Push DevOps-Project-11
2 parents a97bb62 + fe903fa commit b204b78

32 files changed

+1268
-0
lines changed

DevOps Project-11/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Two-Tier AWS Infrastructure with Terraform
2+
[![LinkedIn](https://img.shields.io/badge/Connect%20with%20me%20on-LinkedIn-blue.svg)](https://www.linkedin.com/in/harshhaa-vardhan-reddy/)
3+
[![GitHub](https://img.shields.io/github/stars/NotHarshhaa.svg?style=social)](https://github.com/NotHarshhaa)
4+
[![AWS](https://img.shields.io/badge/AWS-%F0%9F%9B%A1-orange)](https://aws.amazon.com)
5+
[![Terraform](https://img.shields.io/badge/Terraform-%E2%9C%A8-lightgrey)](https://www.terraform.io)
6+
7+
![two-tier](https://imgur.com/X4dGBg6.gif)
8+
9+
## Overview
10+
11+
Welcome to the Terraform project for deploying a Two-Tier architecture on AWS! This project adopts a modular and security-enhanced approach to create a scalable and maintainable infrastructure.
12+
13+
## Features
14+
15+
- **Modular Structure:** The project is organized into dedicated modules for each AWS service, promoting reusability and maintainability.
16+
- **Security Focus:** Utilize IAM roles and policies to ensure a secure infrastructure.
17+
- **Infrastructure as Code (IaC):** Deploy and manage your infrastructure using Terraform, enabling version control and reproducibility.
18+
- **Service-Specific Modules:** Each module corresponds to a specific AWS service, allowing for targeted management.
19+
20+
## Getting Started
21+
22+
Follow these steps to deploy the Two-Tier architecture:
23+
24+
1. **Clone the Repository:**
25+
26+
```bash
27+
git clone https://github.com/NotHarshhaa/DevOps-Projects
28+
cd DevOps-Projects/DevOps Project-11/
29+
```
30+
31+
2. **Plan and Apply:**
32+
```bash
33+
terraform init
34+
terraform plan -var-file=variables.tfvars
35+
terraform apply -var-file=variables.tfvars --auto-approve
36+
```
37+
38+
3. **Cleanup:**
39+
When done the exploration, run the following to destroy the infrastructure
40+
```bash
41+
terraform destroy -var-file=variables.tfvars --auto-approve
42+
```
43+
44+
## Project Highlights
45+
46+
- **VPC: The Foundation**: Create a robust Virtual Private Cloud (VPC) to establish a secure and isolated environment for your application.
47+
48+
- **Load Balancing Magic**: Harness the power of the Application Load Balancer (ALB) to intelligently distribute incoming traffic across multiple EC2 instances, ensuring optimal performance and high availability.
49+
50+
- **Auto Scaling Wonders**: Leverage the Auto Scaling Group to dynamically adjust the number of EC2 instances based on demand. This ensures your application scales seamlessly, providing resilience and cost efficiency.
51+
52+
- **Database Sorcery**: Dive into the world of managed databases with Amazon RDS. Easily deploy, scale, and manage relational databases without the operational overhead.
53+
54+
- **DNS Mastery**: Achieve domain registration and DNS management excellence with Amazon Route 53. Seamlessly connect your applications to the internet while ensuring high availability and low-latency responses.
55+
56+
- **Web Application Firewall (WAF) Protection**: Safeguard your applications from web exploits and ensure a secure user experience with AWS WAF, a web application firewall that helps protect your web applications from common web exploits.
57+
58+
- **Content Delivery Network (CDN) Acceleration**: Boost the delivery of your content globally with a Content Delivery Network. Accelerate load times, enhance user experience, and reduce latency using Amazon CloudFront.
59+
60+
- **SSL Certificate Management with ACM**: Ensure secure communication between your users and the application with Amazon Certificate Manager (ACM). Easily provision, manage, and deploy SSL/TLS certificates.
61+
62+
- **IAM for Robust Security**: Implement robust security measures with Identity and Access Management (IAM). Define granular permissions and access controls to secure your AWS resources.
63+
64+
- **Infrastructure as Code (IaC) Excellence**: Embrace Infrastructure as Code (IaC) with Terraform, facilitating the provisioning and management of AWS resources in a declarative and scalable manner.
65+
66+
These project highlights showcase the comprehensive AWS services integrated into the Two-Tier architecture, providing a solid foundation for your applications with security, scalability, and performance at the forefront.
67+
68+
69+
## Detailed Guide
70+
71+
For an in-depth walkthrough of the project, check out the detailed guide on [Hashnode](https://harshhaa.hashnode.dev/deploy-two-tier-architecture-on-aws-using-terraform).
72+
73+
## Connect with Me
74+
75+
- GitHub: [GitHub Profile](https://github.com/NotHarshhaa)
76+
- LinkedIn: [LinkedIn Profile](https://www.linkedin.com/in/harshhaa-vardhan-reddy/)
77+
78+
## Contributions
79+
80+
Feel free to contribute and adapt this project to suit your needs. We welcome your ideas and improvements.
81+
82+
## License
83+
84+
This project is licensed under the [MIT License](LICENSE).

DevOps Project-11/backend.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
terraform {
2+
backend "s3" {
3+
bucket = "my-ews-baket1"
4+
region = "us-east-1"
5+
key = "DevOps Project-11/terraform.tfstate"
6+
dynamodb_table = "Lock-Files"
7+
encrypt = true
8+
}
9+
required_version = ">=0.13.0"
10+
required_providers {
11+
aws = {
12+
version = ">= 2.7.0"
13+
source = "hashicorp/aws"
14+
}
15+
}
16+
}

DevOps Project-11/main.tf

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
module "vpc" {
2+
source = "../modules/aws-vpc"
3+
4+
vpc-name = var.VPC-NAME
5+
vpc-cidr = var.VPC-CIDR
6+
igw-name = var.IGW-NAME
7+
public-cidr1 = var.PUBLIC-CIDR1
8+
public-subnet1 = var.PUBLIC-SUBNET1
9+
public-cidr2 = var.PUBLIC-CIDR2
10+
public-subnet2 = var.PUBLIC-SUBNET2
11+
private-cidr1 = var.PRIVATE-CIDR1
12+
private-subnet1 = var.PRIVATE-SUBNET1
13+
private-cidr2 = var.PRIVATE-CIDR2
14+
private-subnet2 = var.PRIVATE-SUBNET2
15+
eip-name1 = var.EIP-NAME1
16+
eip-name2 = var.EIP-NAME2
17+
18+
ngw-name1 = var.NGW-NAME1
19+
ngw-name2 = var.NGW-NAME2
20+
public-rt-name1 = var.PUBLIC-RT-NAME1
21+
public-rt-name2 = var.PUBLIC-RT-NAME2
22+
private-rt-name1 = var.PRIVATE-RT-NAME1
23+
private-rt-name2 = var.PRIVATE-RT-NAME2
24+
}
25+
26+
module "security-group" {
27+
source = "../modules/security-group"
28+
29+
vpc-name = var.VPC-NAME
30+
alb-sg-name = var.ALB-SG-NAME
31+
web-sg-name = var.WEB-SG-NAME
32+
db-sg-name = var.DB-SG-NAME
33+
34+
depends_on = [module.vpc]
35+
}
36+
37+
module "rds" {
38+
source = "../modules/aws-rds"
39+
40+
sg-name = var.SG-NAME
41+
private-subnet-name1 = var.PRIVATE-SUBNET1
42+
private-subnet-name2 = var.PRIVATE-SUBNET2
43+
db-sg-name = var.DB-SG-NAME
44+
rds-username = var.RDS-USERNAME
45+
rds-pwd = var.RDS-PWD
46+
db-name = var.DB-NAME
47+
rds-name = var.RDS-NAME
48+
49+
depends_on = [module.security-group]
50+
}
51+
52+
module "alb" {
53+
source = "../modules/alb-tg"
54+
55+
public-subnet-name1 = var.PUBLIC-SUBNET1
56+
public-subnet-name2 = var.PUBLIC-SUBNET2
57+
web-alb-sg-name = var.ALB-SG-NAME
58+
alb-name = var.ALB-NAME
59+
tg-name = var.TG-NAME
60+
vpc-name = var.VPC-NAME
61+
62+
depends_on = [module.rds]
63+
}
64+
65+
module "iam" {
66+
source = "../modules/aws-iam"
67+
68+
iam-role = var.IAM-ROLE
69+
iam-policy = var.IAM-POLICY
70+
instance-profile-name = var.INSTANCE-PROFILE-NAME
71+
72+
depends_on = [module.alb]
73+
}
74+
75+
module "autoscaling" {
76+
source = "../modules/aws-autoscaling"
77+
78+
ami_name = var.AMI-NAME
79+
launch-template-name = var.LAUNCH-TEMPLATE-NAME
80+
instance-profile-name = var.INSTANCE-PROFILE-NAME
81+
web-sg-name = var.WEB-SG-NAME
82+
tg-name = var.TG-NAME
83+
iam-role = var.IAM-ROLE
84+
public-subnet-name1 = var.PUBLIC-SUBNET1
85+
public-subnet-name2 = var.PUBLIC-SUBNET2
86+
asg-name = var.ASG-NAME
87+
88+
depends_on = [module.iam]
89+
}
90+
91+
module "route53" {
92+
source = "../modules/aws-waf-cdn-acm-route53"
93+
94+
domain-name = var.DOMAIN-NAME
95+
cdn-name = var.CDN-NAME
96+
alb-name = var.ALB-NAME
97+
web_acl_name = var.WEB-ACL-NAME
98+
99+
depends_on = [ module.autoscaling ]
100+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
data "aws_subnet" "public-subnet1" {
2+
filter {
3+
name = "tag:Name"
4+
values = [var.public-subnet-name1]
5+
}
6+
}
7+
8+
data "aws_subnet" "public-subnet2" {
9+
filter {
10+
name = "tag:Name"
11+
values = [var.public-subnet-name2]
12+
}
13+
}
14+
15+
data "aws_security_group" "web-alb-sg" {
16+
filter {
17+
name = "tag:Name"
18+
values = [var.web-alb-sg-name]
19+
}
20+
}
21+
22+
data "aws_vpc" "vpc" {
23+
filter {
24+
name = "tag:Name"
25+
values = [var.vpc-name]
26+
}
27+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Creating ALB for Web Tier
2+
resource "aws_lb" "web-elb" {
3+
name = var.alb-name
4+
internal = false
5+
load_balancer_type = "application"
6+
subnets = [data.aws_subnet.public-subnet1.id, data.aws_subnet.public-subnet2.id]
7+
security_groups = [data.aws_security_group.web-alb-sg.id]
8+
ip_address_type = "ipv4"
9+
enable_deletion_protection = false
10+
tags = {
11+
Name = var.alb-name
12+
}
13+
}
14+
15+
# Creating Target Group for Web-Tier
16+
resource "aws_lb_target_group" "web-tg" {
17+
name = var.tg-name
18+
health_check {
19+
enabled = true
20+
interval = 10
21+
path = "/"
22+
protocol = "HTTP"
23+
timeout = 5
24+
healthy_threshold = 5
25+
unhealthy_threshold = 2
26+
}
27+
target_type = "instance"
28+
port = 80
29+
protocol = "HTTP"
30+
vpc_id = data.aws_vpc.vpc.id
31+
32+
tags = {
33+
Name = var.tg-name
34+
}
35+
36+
lifecycle {
37+
prevent_destroy = false
38+
}
39+
depends_on = [ aws_lb.web-elb ]
40+
}
41+
42+
43+
# Creating ALB listener with port 80 and attaching it to Web-Tier Target Group
44+
resource "aws_lb_listener" "web-alb-listener" {
45+
load_balancer_arn = aws_lb.web-elb.arn
46+
port = 80
47+
protocol = "HTTP"
48+
49+
default_action {
50+
type = "forward"
51+
target_group_arn = aws_lb_target_group.web-tg.arn
52+
}
53+
54+
depends_on = [ aws_lb.web-elb ]
55+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
variable "public-subnet-name1" {}
2+
variable "public-subnet-name2" {}
3+
variable "web-alb-sg-name" {}
4+
variable "alb-name" {}
5+
variable "tg-name" {}
6+
variable "vpc-name" {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
apt-get update -y
4+
apt-get upgrade -y
5+
apt-get -y install nginx
6+
cd /var/www/html
7+
wget https://www.tooplate.com/zip-templates/2135_mini_finance.zip
8+
apt install unzip
9+
unzip 2135_mini_finance.zip
10+
rm -rf 2135_mini_finance.zip index.nginx-debian.html
11+
cd 2135_mini_finance/
12+
mv * ../
13+
rm -rf 2135_mini_finance/
14+
systemctl enable nginx
15+
systemctl restart nginx
16+
apt install mysql-server -y
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
data "aws_ami" "ami" {
2+
most_recent = true
3+
4+
filter {
5+
name = "name"
6+
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
7+
}
8+
9+
owners = ["099720109477"]
10+
}
11+
12+
data "aws_security_group" "web-sg" {
13+
filter {
14+
name = "tag:Name"
15+
values = [var.web-sg-name]
16+
}
17+
}
18+
19+
data "aws_subnet" "public-subnet1" {
20+
filter {
21+
name = "tag:Name"
22+
values = [var.public-subnet-name1]
23+
}
24+
}
25+
26+
data "aws_subnet" "public-subnet2" {
27+
filter {
28+
name = "tag:Name"
29+
values = [var.public-subnet-name2]
30+
}
31+
}
32+
33+
data "aws_lb_target_group" "tg" {
34+
tags = {
35+
Name = var.tg-name
36+
}
37+
}
38+
39+
data "aws_iam_instance_profile" "instance-profile" {
40+
name = var.instance-profile-name
41+
}

0 commit comments

Comments
 (0)