From 8883407b9991c28bd1211875a5a4cf95376d947b Mon Sep 17 00:00:00 2001 From: pratpatt1992 Date: Wed, 25 Mar 2026 07:47:40 +0530 Subject: [PATCH 01/33] Initial commit --- main.tf | 2 +- outputs.tf | 12 ++++++------ variables.tf | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/main.tf b/main.tf index 9b32ce06bb..93b6f4ee79 100644 --- a/main.tf +++ b/main.tf @@ -16,7 +16,7 @@ data "aws_ami" "app_ami" { resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id - instance_type = "t3.nano" + instance_type = variable.instance_type tags = { Name = "HelloWorld" diff --git a/outputs.tf b/outputs.tf index b35171bef1..c429b19b48 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,7 +1,7 @@ -#output "instance_ami" { -# value = aws_instance.web.ami -#} +output "instance_ami" { + value = aws_instance.web.ami +} -#output "instance_arn" { -# value = aws_instance.web.arn -#} +output "instance_arn" { + value = aws_instance.web.arn +} diff --git a/variables.tf b/variables.tf index c750667e0f..60856bc925 100644 --- a/variables.tf +++ b/variables.tf @@ -1,4 +1,4 @@ -#variable "instance_type" { -# description = "Type of EC2 instance to provision" -# default = "t3.nano" -#} +variable "instance_type" { + description = "Type of EC2 instance to provision" + default = "t3.nano" +} From ff4e059ea9d5330141f42cc4f99673a47bb68922 Mon Sep 17 00:00:00 2001 From: pratpatt1992 Date: Wed, 25 Mar 2026 07:56:38 +0530 Subject: [PATCH 02/33] 2nd commit --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 93b6f4ee79..0bfc354510 100644 --- a/main.tf +++ b/main.tf @@ -16,7 +16,7 @@ data "aws_ami" "app_ami" { resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id - instance_type = variable.instance_type + instance_type = var.instance_type tags = { Name = "HelloWorld" From 074a2bb39cd0b39f101b6e81bda46a7e32291c92 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Mon, 20 Apr 2026 08:23:18 +0530 Subject: [PATCH 03/33] Update EC2 instance type for AWS Free Tier --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 60856bc925..676e5cf915 100644 --- a/variables.tf +++ b/variables.tf @@ -1,4 +1,4 @@ variable "instance_type" { description = "Type of EC2 instance to provision" - default = "t3.nano" + default = "t2.micro" } From edaa4461105b6880cbb259a27380f9b87a7a6baf Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Mon, 20 Apr 2026 08:41:13 +0530 Subject: [PATCH 04/33] Updating AMi to Amazon linux 2 ami --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 0bfc354510..0040968c9e 100644 --- a/main.tf +++ b/main.tf @@ -3,7 +3,7 @@ data "aws_ami" "app_ami" { filter { name = "name" - values = ["bitnami-tomcat-*-x86_64-hvm-ebs-nami"] + values = ["amzn2-ami-hvm-*-x86_64-gp2"] } filter { @@ -11,7 +11,7 @@ data "aws_ami" "app_ami" { values = ["hvm"] } - owners = ["979382823631"] # Bitnami + owners = ["137112412989"] # Amazon } resource "aws_instance" "web" { From 2d1b84fb2a0e1caf4040aa67c1bbcc21c6f0d1ff Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Mon, 20 Apr 2026 08:45:36 +0530 Subject: [PATCH 05/33] update aws region for free tier --- providers.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers.tf b/providers.tf index c41e3650b5..2c9e2f0d37 100644 --- a/providers.tf +++ b/providers.tf @@ -7,5 +7,5 @@ terraform { } provider "aws" { - region = "us-west-2" + region = "us-east-1" } From 816ee598e41b3048be2a89918c81e5263fc1159c Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Mon, 20 Apr 2026 09:04:31 +0530 Subject: [PATCH 06/33] Update AMi name for free tier --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 0040968c9e..f49b7b11b0 100644 --- a/main.tf +++ b/main.tf @@ -3,7 +3,7 @@ data "aws_ami" "app_ami" { filter { name = "name" - values = ["amzn2-ami-hvm-*-x86_64-gp2"] + values = ["al2023-ami-2023.11.20260413.0-kernel-6.1-x86_64"] } filter { From ad7538214f212364a93585aba0a15c424b8f0e98 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Mon, 20 Apr 2026 09:10:33 +0530 Subject: [PATCH 07/33] update instace to t3.micro --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 676e5cf915..36cfe64a08 100644 --- a/variables.tf +++ b/variables.tf @@ -1,4 +1,4 @@ variable "instance_type" { description = "Type of EC2 instance to provision" - default = "t2.micro" + default = "t3.micro" } From 038e76079445c8b9546cd075ee93d308bd05b2ba Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Tue, 21 Apr 2026 09:57:28 +0530 Subject: [PATCH 08/33] Update EC2 instance type to t3.small --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 36cfe64a08..57c835fdf0 100644 --- a/variables.tf +++ b/variables.tf @@ -1,4 +1,4 @@ variable "instance_type" { description = "Type of EC2 instance to provision" - default = "t3.micro" + default = "t3.small" } From 954c3ad2820c452e88282b20ec65349d91b52701 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Wed, 22 Apr 2026 08:43:58 +0530 Subject: [PATCH 09/33] create security groups --- main.tf | 47 +++++++++++++++++++++++++++++++++++++++++++++++ test.tf | 0 2 files changed, 47 insertions(+) create mode 100644 test.tf diff --git a/main.tf b/main.tf index f49b7b11b0..4456516c74 100644 --- a/main.tf +++ b/main.tf @@ -18,7 +18,54 @@ resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type + vpc_security_group_ids = [aws_security_group.blog.id] + tags = { Name = "HelloWorld" } } + +resource "aws_vpc" "default"{ + default = true # regions default VPC +} + +resource "aws_security_group" "blog" { + name = "blog" + description = "Allow http and https in. Allow everything out" + + tags = { + terraform = "true" + } + + vpc_id = data.aws_vpc.default.id +} + +resource "aws_security_group_rule" "blog_http_in" { +type = "ingress" +from_port = 80 +to_port = 80 +protocol = "tcp" +cidr_blocks = ["0.0.0.0/0] + +security_group_id = aws_security_group.blog.id +} + +resource "aws_security_group_rule" "blog_https_in" { +type = "ingress" +from_port = 443 +to_port = 443 +protocol = "tcp" +cidr_blocks = ["0.0.0.0/0] + +security_group_id = aws_security_group.blog.id +} + +resource "aws_security_group_rule" "blog_everything_out" { +type = "egress" +from_port = 0 +to_port = 0 +protocol = -1 +cidr_blocks = ["0.0.0.0/0] + +security_group_id = aws_security_group.blog.id +} \ No newline at end of file diff --git a/test.tf b/test.tf new file mode 100644 index 0000000000..e69de29bb2 From 23db94d6f334373139728114e36a2d52d5248a0e Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Wed, 22 Apr 2026 08:45:29 +0530 Subject: [PATCH 10/33] update security group --- main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index 4456516c74..48ee0e2afa 100644 --- a/main.tf +++ b/main.tf @@ -45,7 +45,7 @@ type = "ingress" from_port = 80 to_port = 80 protocol = "tcp" -cidr_blocks = ["0.0.0.0/0] +cidr_blocks = ["0.0.0.0/0"] security_group_id = aws_security_group.blog.id } @@ -55,7 +55,7 @@ type = "ingress" from_port = 443 to_port = 443 protocol = "tcp" -cidr_blocks = ["0.0.0.0/0] +cidr_blocks = ["0.0.0.0/0"] security_group_id = aws_security_group.blog.id } @@ -65,7 +65,7 @@ type = "egress" from_port = 0 to_port = 0 protocol = -1 -cidr_blocks = ["0.0.0.0/0] +cidr_blocks = ["0.0.0.0/0"]" security_group_id = aws_security_group.blog.id } \ No newline at end of file From ee80d16865690b166fc1b45197b88a6f509d4d35 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Wed, 22 Apr 2026 08:47:46 +0530 Subject: [PATCH 11/33] update security group tf --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 48ee0e2afa..c5aa8be3f4 100644 --- a/main.tf +++ b/main.tf @@ -65,7 +65,7 @@ type = "egress" from_port = 0 to_port = 0 protocol = -1 -cidr_blocks = ["0.0.0.0/0"]" +cidr_blocks = ["0.0.0.0/0"] security_group_id = aws_security_group.blog.id } \ No newline at end of file From 9958efc684570020fc840ea4b79de2ed4c23a34d Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Wed, 22 Apr 2026 08:51:30 +0530 Subject: [PATCH 12/33] update default vpc --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index c5aa8be3f4..7824b1d1c3 100644 --- a/main.tf +++ b/main.tf @@ -26,7 +26,7 @@ resource "aws_instance" "web" { } resource "aws_vpc" "default"{ - default = true # regions default VPC + default = true } resource "aws_security_group" "blog" { From d152a65f116168df618ecc9c0f5c469886c2e1d7 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Wed, 22 Apr 2026 08:55:15 +0530 Subject: [PATCH 13/33] update tf to add security group --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 7824b1d1c3..9839156e41 100644 --- a/main.tf +++ b/main.tf @@ -25,7 +25,7 @@ resource "aws_instance" "web" { } } -resource "aws_vpc" "default"{ +data "aws_vpc" "default"{ default = true } From fdfd515aba7bb6a133bd6bfc0564e5fdeb21b029 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Thu, 23 Apr 2026 08:36:50 +0530 Subject: [PATCH 14/33] Adding security group module --- main.tf | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 9839156e41..114a31f0b6 100644 --- a/main.tf +++ b/main.tf @@ -18,7 +18,7 @@ resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type - vpc_security_group_ids = [aws_security_group.blog.id] + vpc_security_group_ids = [module.blog_sg.security_group_id] tags = { Name = "HelloWorld" @@ -29,6 +29,20 @@ data "aws_vpc" "default"{ default = true } +module "blog_sg" { +source = "terraform-aws-modules/security-group/aws" +version = "5.3.1" +name = "blog_new" + +vpc_id = data.aws_vpc.default.id + +ingress_rules = ["http-80-tcp","https-443-tcp"] +ingress_cidr_blocks = [0.0.0.0/0] + +egress_rules = ["all-all"] +egress_cidr_blocks = [0.0.0.0/0] +} + resource "aws_security_group" "blog" { name = "blog" description = "Allow http and https in. Allow everything out" From 74b83e2294b62520f6ad6f79e65324424e3213b0 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Fri, 24 Apr 2026 08:13:10 +0530 Subject: [PATCH 15/33] updating ingress and egress rules --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 114a31f0b6..4bc796d0f2 100644 --- a/main.tf +++ b/main.tf @@ -37,10 +37,10 @@ name = "blog_new" vpc_id = data.aws_vpc.default.id ingress_rules = ["http-80-tcp","https-443-tcp"] -ingress_cidr_blocks = [0.0.0.0/0] +ingress_cidr_blocks = ["0.0.0.0/0"] egress_rules = ["all-all"] -egress_cidr_blocks = [0.0.0.0/0] +egress_cidr_blocks = ["0.0.0.0/0"] } resource "aws_security_group" "blog" { From 4322d2ea0533718681063b3a361df0e8d2aa510c Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Fri, 24 Apr 2026 08:25:56 +0530 Subject: [PATCH 16/33] removing old rules --- main.tf | 80 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/main.tf b/main.tf index 4bc796d0f2..77789d179d 100644 --- a/main.tf +++ b/main.tf @@ -43,43 +43,43 @@ egress_rules = ["all-all"] egress_cidr_blocks = ["0.0.0.0/0"] } -resource "aws_security_group" "blog" { - name = "blog" - description = "Allow http and https in. Allow everything out" - - tags = { - terraform = "true" - } - - vpc_id = data.aws_vpc.default.id -} - -resource "aws_security_group_rule" "blog_http_in" { -type = "ingress" -from_port = 80 -to_port = 80 -protocol = "tcp" -cidr_blocks = ["0.0.0.0/0"] - -security_group_id = aws_security_group.blog.id -} - -resource "aws_security_group_rule" "blog_https_in" { -type = "ingress" -from_port = 443 -to_port = 443 -protocol = "tcp" -cidr_blocks = ["0.0.0.0/0"] - -security_group_id = aws_security_group.blog.id -} - -resource "aws_security_group_rule" "blog_everything_out" { -type = "egress" -from_port = 0 -to_port = 0 -protocol = -1 -cidr_blocks = ["0.0.0.0/0"] - -security_group_id = aws_security_group.blog.id -} \ No newline at end of file +# resource "aws_security_group" "blog" { +# name = "blog" +# description = "Allow http and https in. Allow everything out" + +# tags = { +# terraform = "true" +# } + +# vpc_id = data.aws_vpc.default.id +# } + +# resource "aws_security_group_rule" "blog_http_in" { +# type = "ingress" +# from_port = 80 +# to_port = 80 +# protocol = "tcp" +# cidr_blocks = ["0.0.0.0/0"] + +# security_group_id = aws_security_group.blog.id +# } + +# resource "aws_security_group_rule" "blog_https_in" { +# type = "ingress" +# from_port = 443 +# to_port = 443 +# protocol = "tcp" +# cidr_blocks = ["0.0.0.0/0"] + +# security_group_id = aws_security_group.blog.id +# } + +# resource "aws_security_group_rule" "blog_everything_out" { +# type = "egress" +# from_port = 0 +# to_port = 0 +# protocol = -1 +# cidr_blocks = ["0.0.0.0/0"] + +# security_group_id = aws_security_group.blog.id +# } \ No newline at end of file From dbf1458423d8049729944c764b7ebb8c15f4bffe Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Fri, 24 Apr 2026 08:29:51 +0530 Subject: [PATCH 17/33] updating security group to allow all ingress --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 77789d179d..574b5c2162 100644 --- a/main.tf +++ b/main.tf @@ -36,7 +36,7 @@ name = "blog_new" vpc_id = data.aws_vpc.default.id -ingress_rules = ["http-80-tcp","https-443-tcp"] +ingress_rules = ["http-80-tcp","https-443-tcp","all-all"] ingress_cidr_blocks = ["0.0.0.0/0"] egress_rules = ["all-all"] From 02918c378f06ee696e92d41a6544d959eb59f395 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Fri, 24 Apr 2026 08:46:32 +0530 Subject: [PATCH 18/33] remove all ingress access --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 574b5c2162..77789d179d 100644 --- a/main.tf +++ b/main.tf @@ -36,7 +36,7 @@ name = "blog_new" vpc_id = data.aws_vpc.default.id -ingress_rules = ["http-80-tcp","https-443-tcp","all-all"] +ingress_rules = ["http-80-tcp","https-443-tcp"] ingress_cidr_blocks = ["0.0.0.0/0"] egress_rules = ["all-all"] From b43f83523f87eba7b967a3140e7b6f45cc50d75e Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Fri, 24 Apr 2026 09:02:37 +0530 Subject: [PATCH 19/33] Create a DEV VPC --- main.tf | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index 77789d179d..5e7a9cc381 100644 --- a/main.tf +++ b/main.tf @@ -17,7 +17,7 @@ data "aws_ami" "app_ami" { resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type - + subnet_id = module.blog_vpc.public_subnets[0] vpc_security_group_ids = [module.blog_sg.security_group_id] tags = { @@ -25,8 +25,22 @@ resource "aws_instance" "web" { } } -data "aws_vpc" "default"{ - default = true +module "blog_vpc" { + source = "terraform-aws-modules/vpc/aws" + + name = "dev" + cidr = "10.0.0.0/16" + + azs = ["us-east-1a", "us-east-1b", "us-east-1c"] + private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] + public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] + + enable_nat_gateway = true + + tags = { + Terraform = "true" + Environment = "dev" + } } module "blog_sg" { @@ -34,7 +48,7 @@ source = "terraform-aws-modules/security-group/aws" version = "5.3.1" name = "blog_new" -vpc_id = data.aws_vpc.default.id +vpc_id = module.blog_vpc.vpc_id ingress_rules = ["http-80-tcp","https-443-tcp"] ingress_cidr_blocks = ["0.0.0.0/0"] From 6f4ccf02210937198553896ffa22b4a7f57b29b0 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 07:50:47 +0530 Subject: [PATCH 20/33] Add Load Balancer --- main.tf | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 5e7a9cc381..9917c93e1d 100644 --- a/main.tf +++ b/main.tf @@ -50,13 +50,49 @@ name = "blog_new" vpc_id = module.blog_vpc.vpc_id -ingress_rules = ["http-80-tcp","https-443-tcp"] +ingress_rules = ["http-80-tcp","https-443-tcp","all-all"] ingress_cidr_blocks = ["0.0.0.0/0"] egress_rules = ["all-all"] egress_cidr_blocks = ["0.0.0.0/0"] } +module "blog_alb" { + source = "terraform-aws-modules/alb/aws" + + name = "blog-alb" + vpc_id = module.blog_vpc.vpc_id + subnets = module.blog_vpc.public_subnets + + security_groups = [module.blog_sg.security_group_id] + + listeners = { + blog-http = { + port = 80 + protocol = "HTTP" + forward = { + target_group_arn = aws_lb_target_group.blog.arn + } + } + } + tags = { + Environment = "Dev" + } +} + +resource "aws_lb_target_group" "blog" { + name = "blog-tg" + port = 80 + protocol = "HTTP" + vpc_id = module.blog_vpc.vpc_id +} + +resource "aws_lb_target_group_attachment" "blog" { + target_group_arn = aws_lb_target_group.blog.arn + target_id = aws_instance.blog.id + port = 80 +} + # resource "aws_security_group" "blog" { # name = "blog" # description = "Allow http and https in. Allow everything out" From d9fbfb2fe58971e0ced3c631fdcb3fe46e4fb071 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 07:53:01 +0530 Subject: [PATCH 21/33] Add Load Balancer --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 9917c93e1d..30fae6749d 100644 --- a/main.tf +++ b/main.tf @@ -14,7 +14,7 @@ data "aws_ami" "app_ami" { owners = ["137112412989"] # Amazon } -resource "aws_instance" "web" { +resource "aws_instance" "blog" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type subnet_id = module.blog_vpc.public_subnets[0] From e1870f606b4dc1efdf4b2aa8850b5839c02f2603 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 07:55:01 +0530 Subject: [PATCH 22/33] update ALB --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 30fae6749d..4f4ba4ea0b 100644 --- a/main.tf +++ b/main.tf @@ -14,7 +14,7 @@ data "aws_ami" "app_ami" { owners = ["137112412989"] # Amazon } -resource "aws_instance" "blog" { +resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type subnet_id = module.blog_vpc.public_subnets[0] @@ -89,7 +89,7 @@ resource "aws_lb_target_group" "blog" { resource "aws_lb_target_group_attachment" "blog" { target_group_arn = aws_lb_target_group.blog.arn - target_id = aws_instance.blog.id + target_id = aws_instance.web.id port = 80 } From e3e748cd969be23d342621ef642a2a7a72decade Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 08:04:36 +0530 Subject: [PATCH 23/33] remove ALB --- main.tf | 66 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/main.tf b/main.tf index 4f4ba4ea0b..33f9a430e7 100644 --- a/main.tf +++ b/main.tf @@ -57,41 +57,41 @@ egress_rules = ["all-all"] egress_cidr_blocks = ["0.0.0.0/0"] } -module "blog_alb" { - source = "terraform-aws-modules/alb/aws" - - name = "blog-alb" - vpc_id = module.blog_vpc.vpc_id - subnets = module.blog_vpc.public_subnets - - security_groups = [module.blog_sg.security_group_id] - - listeners = { - blog-http = { - port = 80 - protocol = "HTTP" - forward = { - target_group_arn = aws_lb_target_group.blog.arn - } - } - } - tags = { - Environment = "Dev" - } -} +# module "blog_alb" { +# source = "terraform-aws-modules/alb/aws" + +# name = "blog-alb" +# vpc_id = module.blog_vpc.vpc_id +# subnets = module.blog_vpc.public_subnets + +# security_groups = [module.blog_sg.security_group_id] + +# listeners = { +# blog-http = { +# port = 80 +# protocol = "HTTP" +# forward = { +# target_group_arn = aws_lb_target_group.blog.arn +# } +# } +# } +# tags = { +# Environment = "Dev" +# } +# } -resource "aws_lb_target_group" "blog" { - name = "blog-tg" - port = 80 - protocol = "HTTP" - vpc_id = module.blog_vpc.vpc_id -} +# resource "aws_lb_target_group" "blog" { +# name = "blog-tg" +# port = 80 +# protocol = "HTTP" +# vpc_id = module.blog_vpc.vpc_id +# } -resource "aws_lb_target_group_attachment" "blog" { - target_group_arn = aws_lb_target_group.blog.arn - target_id = aws_instance.web.id - port = 80 -} +# resource "aws_lb_target_group_attachment" "blog" { +# target_group_arn = aws_lb_target_group.blog.arn +# target_id = aws_instance.web.id +# port = 80 +# } # resource "aws_security_group" "blog" { # name = "blog" From e1617b4fc291ec1ad7b77746172d77337a423387 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 08:08:56 +0530 Subject: [PATCH 24/33] delete ALB --- main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/main.tf b/main.tf index 33f9a430e7..1a949861fc 100644 --- a/main.tf +++ b/main.tf @@ -57,6 +57,7 @@ egress_rules = ["all-all"] egress_cidr_blocks = ["0.0.0.0/0"] } + # module "blog_alb" { # source = "terraform-aws-modules/alb/aws" From bcd6169a7e42392720c385334794feca7d3e3978 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 08:20:19 +0530 Subject: [PATCH 25/33] remove VPC --- main.tf | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/main.tf b/main.tf index 1a949861fc..3803aea944 100644 --- a/main.tf +++ b/main.tf @@ -17,7 +17,7 @@ data "aws_ami" "app_ami" { resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type - subnet_id = module.blog_vpc.public_subnets[0] + # subnet_id = module.blog_vpc.public_subnets[0] vpc_security_group_ids = [module.blog_sg.security_group_id] tags = { @@ -25,30 +25,35 @@ resource "aws_instance" "web" { } } -module "blog_vpc" { - source = "terraform-aws-modules/vpc/aws" +data "aws_vpc" "blog" { + default = true +} - name = "dev" - cidr = "10.0.0.0/16" +# module "blog_vpc" { +# source = "terraform-aws-modules/vpc/aws" - azs = ["us-east-1a", "us-east-1b", "us-east-1c"] - private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] - public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] +# name = "dev" +# cidr = "10.0.0.0/16" - enable_nat_gateway = true +# azs = ["us-east-1a", "us-east-1b", "us-east-1c"] +# private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] +# public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] - tags = { - Terraform = "true" - Environment = "dev" - } -} +# enable_nat_gateway = true + + +# tags = { +# Terraform = "true" +# Environment = "dev" +# } +# } module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.1" name = "blog_new" -vpc_id = module.blog_vpc.vpc_id +vpc_id = data.aws_vpc.blog.id ingress_rules = ["http-80-tcp","https-443-tcp","all-all"] ingress_cidr_blocks = ["0.0.0.0/0"] From 266404862914850d560ac5959bc5eaf8aba9242d Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 08:30:02 +0530 Subject: [PATCH 26/33] updating EC2 name --- main.tf | 3 ++- outputs.tf | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index 3803aea944..995e6a1c5e 100644 --- a/main.tf +++ b/main.tf @@ -14,7 +14,7 @@ data "aws_ami" "app_ami" { owners = ["137112412989"] # Amazon } -resource "aws_instance" "web" { +resource "aws_instance" "blog" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type # subnet_id = module.blog_vpc.public_subnets[0] @@ -54,6 +54,7 @@ version = "5.3.1" name = "blog_new" vpc_id = data.aws_vpc.blog.id +# vpc_id = module.blog_vpc.vpc_id ingress_rules = ["http-80-tcp","https-443-tcp","all-all"] ingress_cidr_blocks = ["0.0.0.0/0"] diff --git a/outputs.tf b/outputs.tf index c429b19b48..7e9410b55c 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,7 +1,7 @@ output "instance_ami" { - value = aws_instance.web.ami + value = aws_instance.blog.ami } output "instance_arn" { - value = aws_instance.web.arn + value = aws_instance.blog.arn } From b46ac0142f1cd4adb362ec13b8437213611e7572 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 08:44:14 +0530 Subject: [PATCH 27/33] Add ALB --- main.tf | 104 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/main.tf b/main.tf index 995e6a1c5e..0e0315d1ee 100644 --- a/main.tf +++ b/main.tf @@ -17,7 +17,7 @@ data "aws_ami" "app_ami" { resource "aws_instance" "blog" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type - # subnet_id = module.blog_vpc.public_subnets[0] + subnet_id = module.blog_vpc.public_subnets[0] vpc_security_group_ids = [module.blog_sg.security_group_id] tags = { @@ -29,32 +29,32 @@ data "aws_vpc" "blog" { default = true } -# module "blog_vpc" { -# source = "terraform-aws-modules/vpc/aws" +module "blog_vpc" { + source = "terraform-aws-modules/vpc/aws" -# name = "dev" -# cidr = "10.0.0.0/16" + name = "dev" + cidr = "10.0.0.0/16" -# azs = ["us-east-1a", "us-east-1b", "us-east-1c"] -# private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] -# public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] + azs = ["us-east-1a", "us-east-1b", "us-east-1c"] + private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] + public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] -# enable_nat_gateway = true + enable_nat_gateway = true -# tags = { -# Terraform = "true" -# Environment = "dev" -# } -# } + tags = { + Terraform = "true" + Environment = "dev" + } +} module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.1" name = "blog_new" -vpc_id = data.aws_vpc.blog.id -# vpc_id = module.blog_vpc.vpc_id +# vpc_id = data.aws_vpc.blog.id +vpc_id = module.blog_vpc.vpc_id ingress_rules = ["http-80-tcp","https-443-tcp","all-all"] ingress_cidr_blocks = ["0.0.0.0/0"] @@ -64,49 +64,49 @@ egress_cidr_blocks = ["0.0.0.0/0"] } -# module "blog_alb" { -# source = "terraform-aws-modules/alb/aws" +module "blog_alb" { + source = "terraform-aws-modules/alb/aws" -# name = "blog-alb" -# vpc_id = module.blog_vpc.vpc_id -# subnets = module.blog_vpc.public_subnets + name = "blog-alb" + vpc_id = module.blog_vpc.vpc_id + subnets = module.blog_vpc.public_subnets -# security_groups = [module.blog_sg.security_group_id] + security_groups = [module.blog_sg.security_group_id] -# listeners = { -# blog-http = { -# port = 80 -# protocol = "HTTP" -# forward = { -# target_group_arn = aws_lb_target_group.blog.arn -# } -# } -# } -# tags = { -# Environment = "Dev" -# } -# } + listeners = { + blog-http = { + port = 80 + protocol = "HTTP" + forward = { + target_group_arn = aws_lb_target_group.blog.arn + } + } + } + tags = { + Environment = "Dev" + } +} -# resource "aws_lb_target_group" "blog" { -# name = "blog-tg" -# port = 80 -# protocol = "HTTP" -# vpc_id = module.blog_vpc.vpc_id -# } +resource "aws_lb_target_group" "blog" { + name = "blog-tg" + port = 80 + protocol = "HTTP" + vpc_id = module.blog_vpc.vpc_id +} -# resource "aws_lb_target_group_attachment" "blog" { -# target_group_arn = aws_lb_target_group.blog.arn -# target_id = aws_instance.web.id -# port = 80 -# } +resource "aws_lb_target_group_attachment" "blog" { + target_group_arn = aws_lb_target_group.blog.arn + target_id = aws_instance.web.id + port = 80 +} -# resource "aws_security_group" "blog" { -# name = "blog" -# description = "Allow http and https in. Allow everything out" +resource "aws_security_group" "blog" { + name = "blog" + description = "Allow http and https in. Allow everything out" -# tags = { -# terraform = "true" -# } + tags = { + terraform = "true" + } # vpc_id = data.aws_vpc.default.id # } From 46674f2bd4dba450534ae5d108bf564489893a1a Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 08:45:42 +0530 Subject: [PATCH 28/33] Add ALB --- main.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.tf b/main.tf index 0e0315d1ee..56284f8b3d 100644 --- a/main.tf +++ b/main.tf @@ -100,13 +100,13 @@ resource "aws_lb_target_group_attachment" "blog" { port = 80 } -resource "aws_security_group" "blog" { - name = "blog" - description = "Allow http and https in. Allow everything out" +# resource "aws_security_group" "blog" { +# name = "blog" +# description = "Allow http and https in. Allow everything out" - tags = { - terraform = "true" - } +# tags = { +# terraform = "true" +# } # vpc_id = data.aws_vpc.default.id # } From 9c4855be8b56b79eda5150b3b3dc657bee1bc218 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 08:46:42 +0530 Subject: [PATCH 29/33] Update ALB --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 56284f8b3d..b15d3aeff5 100644 --- a/main.tf +++ b/main.tf @@ -96,7 +96,7 @@ resource "aws_lb_target_group" "blog" { resource "aws_lb_target_group_attachment" "blog" { target_group_arn = aws_lb_target_group.blog.arn - target_id = aws_instance.web.id + target_id = aws_instance.blog.id port = 80 } From 175d69dd720f0dd9e4ae485610a8c7548e4919e9 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 09:12:22 +0530 Subject: [PATCH 30/33] Add autoscaling --- main.tf | 28 +++++++++++++++++++++++++--- outputs.tf | 12 ++++++------ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/main.tf b/main.tf index b15d3aeff5..d7f8e3eccb 100644 --- a/main.tf +++ b/main.tf @@ -25,9 +25,9 @@ resource "aws_instance" "blog" { } } -data "aws_vpc" "blog" { - default = true -} +# data "aws_vpc" "blog" { +# default = true +# } module "blog_vpc" { source = "terraform-aws-modules/vpc/aws" @@ -100,6 +100,28 @@ resource "aws_lb_target_group_attachment" "blog" { port = 80 } +module "blog-autoscaling" { + source = "terraform-aws-modules/autoscaling/aws" + name = "blog" + + min_size = 1 + max_size = 2 + + vpc_zone_identifier = module.blog_vpc.public_subnets + + launch_template_name = "blog" + security_groups = [module.blog_sg.security_group_id] + instance_type = var.instance_type + image_id = data.aws_ami.app_ami.id + + traffic_source_attachments = { + alb = { + traffic_source_identifier = aws_lb_target_group.blog.arn + } + } +} + + # resource "aws_security_group" "blog" { # name = "blog" # description = "Allow http and https in. Allow everything out" diff --git a/outputs.tf b/outputs.tf index 7e9410b55c..5e8a8f2054 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,7 +1,7 @@ -output "instance_ami" { - value = aws_instance.blog.ami -} +# output "instance_ami" { +# value = aws_instance.blog.ami +# } -output "instance_arn" { - value = aws_instance.blog.arn -} +# output "instance_arn" { +# value = aws_instance.blog.arn +# } From 808e62b9f36165bc24a4c627d6cd47a4cc779c9a Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 09:14:19 +0530 Subject: [PATCH 31/33] remove target group attachment --- main.tf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.tf b/main.tf index d7f8e3eccb..b35f02828b 100644 --- a/main.tf +++ b/main.tf @@ -94,11 +94,11 @@ resource "aws_lb_target_group" "blog" { vpc_id = module.blog_vpc.vpc_id } -resource "aws_lb_target_group_attachment" "blog" { - target_group_arn = aws_lb_target_group.blog.arn - target_id = aws_instance.blog.id - port = 80 -} +# resource "aws_lb_target_group_attachment" "blog" { +# target_group_arn = aws_lb_target_group.blog.arn +# target_id = aws_instance.blog.id +# port = 80 +# } module "blog-autoscaling" { source = "terraform-aws-modules/autoscaling/aws" From 60e5efd2d97d7ffe65d3bc33bcef6234b3302402 Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 09:33:20 +0530 Subject: [PATCH 32/33] Update Autoscaling --- main.tf | 64 ++++++++++++++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/main.tf b/main.tf index b35f02828b..e833ff405d 100644 --- a/main.tf +++ b/main.tf @@ -14,16 +14,16 @@ data "aws_ami" "app_ami" { owners = ["137112412989"] # Amazon } -resource "aws_instance" "blog" { - ami = data.aws_ami.app_ami.id - instance_type = var.instance_type - subnet_id = module.blog_vpc.public_subnets[0] - vpc_security_group_ids = [module.blog_sg.security_group_id] +# resource "aws_instance" "blog" { +# ami = data.aws_ami.app_ami.id +# instance_type = var.instance_type +# subnet_id = module.blog_vpc.public_subnets[0] +# vpc_security_group_ids = [module.blog_sg.security_group_id] - tags = { - Name = "HelloWorld" - } -} +# tags = { +# Name = "HelloWorld" +# } +# } # data "aws_vpc" "blog" { # default = true @@ -56,7 +56,7 @@ name = "blog_new" # vpc_id = data.aws_vpc.blog.id vpc_id = module.blog_vpc.vpc_id -ingress_rules = ["http-80-tcp","https-443-tcp","all-all"] +ingress_rules = ["http-80-tcp","https-443-tcp"] ingress_cidr_blocks = ["0.0.0.0/0"] egress_rules = ["all-all"] @@ -73,26 +73,27 @@ module "blog_alb" { security_groups = [module.blog_sg.security_group_id] - listeners = { - blog-http = { - port = 80 - protocol = "HTTP" - forward = { - target_group_arn = aws_lb_target_group.blog.arn - } + target_groups = [ + { + name_prefix = "blog" + backend_port = 80 + backend_protocol = "HTTP" + target_type = "instance" } - } + ] + listeners = [ + { + port = 80 + protocol = "HTTP" + target_group_index = 0 + } + ] tags = { Environment = "Dev" } } -resource "aws_lb_target_group" "blog" { - name = "blog-tg" - port = 80 - protocol = "HTTP" - vpc_id = module.blog_vpc.vpc_id -} + # resource "aws_lb_target_group_attachment" "blog" { # target_group_arn = aws_lb_target_group.blog.arn @@ -108,17 +109,10 @@ module "blog-autoscaling" { max_size = 2 vpc_zone_identifier = module.blog_vpc.public_subnets - - launch_template_name = "blog" - security_groups = [module.blog_sg.security_group_id] - instance_type = var.instance_type - image_id = data.aws_ami.app_ami.id - - traffic_source_attachments = { - alb = { - traffic_source_identifier = aws_lb_target_group.blog.arn - } - } + target_group_arns = module.blog_alb.target_group_arns + security_groups = [module.blog_sg.security_group_id] + instance_type = var.instance_type + image_id = data.aws_ami.app_ami.id } From d1fc6a68a0a21e108462ffcb66437e3033a47dee Mon Sep 17 00:00:00 2001 From: Pratik Pattanaik Date: Sat, 25 Apr 2026 09:36:18 +0530 Subject: [PATCH 33/33] Update ALB and Autoscaling --- main.tf | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/main.tf b/main.tf index e833ff405d..27ca9bb9ff 100644 --- a/main.tf +++ b/main.tf @@ -65,23 +65,22 @@ egress_cidr_blocks = ["0.0.0.0/0"] module "blog_alb" { - source = "terraform-aws-modules/alb/aws" - - name = "blog-alb" - vpc_id = module.blog_vpc.vpc_id - subnets = module.blog_vpc.public_subnets - - security_groups = [module.blog_sg.security_group_id] - + source = "terraform-aws-modules/alb/aws" + version = "~> 6.0" + name = "blog-alb" + load_balancer_type = "application" + vpc_id = module.blog_vpc.vpc_id + subnets = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] target_groups = [ { - name_prefix = "blog" - backend_port = 80 + name_prefix = "blog-" backend_protocol = "HTTP" + backend_port = 80 target_type = "instance" } ] - listeners = [ + http_tcp_listeners = [ { port = 80 protocol = "HTTP" @@ -89,25 +88,22 @@ module "blog_alb" { } ] tags = { - Environment = "Dev" + Environment = "dev" } } - - # resource "aws_lb_target_group_attachment" "blog" { # target_group_arn = aws_lb_target_group.blog.arn # target_id = aws_instance.blog.id # port = 80 # } -module "blog-autoscaling" { +module "blog_autoscaling" { source = "terraform-aws-modules/autoscaling/aws" - name = "blog" - - min_size = 1 - max_size = 2 - + version = "6.5.2" + name = "blog" + min_size = 1 + max_size = 2 vpc_zone_identifier = module.blog_vpc.public_subnets target_group_arns = module.blog_alb.target_group_arns security_groups = [module.blog_sg.security_group_id]