From 86ba1e34e660551a03a3bbb03725cf2b37f555c4 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 23 Jun 2026 19:41:08 +0000 Subject: [PATCH 01/36] update aws ami data resource filter in main.tf --- main.tf | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/main.tf b/main.tf index 9b32ce06bb..35fed841e1 100644 --- a/main.tf +++ b/main.tf @@ -1,24 +1,24 @@ data "aws_ami" "app_ami" { most_recent = true + owners = ["amazon"] filter { name = "name" - values = ["bitnami-tomcat-*-x86_64-hvm-ebs-nami"] + values = ["al2023-ami-2023.*-x86_64"] } filter { - name = "virtualization-type" - values = ["hvm"] + name = "architecture" + values = ["x86_64"] } - owners = ["979382823631"] # Bitnami -} - -resource "aws_instance" "web" { - ami = data.aws_ami.app_ami.id - instance_type = "t3.nano" + filter { + name = "root-device-type" + values = ["ebs"] + } - tags = { - Name = "HelloWorld" + filter { + name = "virtualization-type" + values = ["hvm"] } -} +} \ No newline at end of file From 17ad81e83797dc3207b94d9ee6e467d3a5a3d3bb Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 23 Jun 2026 19:57:45 +0000 Subject: [PATCH 02/36] added AWS instance --- main.tf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.tf b/main.tf index 35fed841e1..3dfbedfb9e 100644 --- a/main.tf +++ b/main.tf @@ -21,4 +21,12 @@ data "aws_ami" "app_ami" { name = "virtualization-type" values = ["hvm"] } + resource "aws_instance" "web" { + ami = data.aws_ami.app_ami.id + instance_type = "t3.nano" + + tags = { + Name = "HelloWorld" + } +} } \ No newline at end of file From 00357bc485dec16e6ea04c7d101edca84e8d6155 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 23 Jun 2026 20:03:11 +0000 Subject: [PATCH 03/36] AWS instances updated --- main.tf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 3dfbedfb9e..98f8c7d008 100644 --- a/main.tf +++ b/main.tf @@ -21,12 +21,13 @@ data "aws_ami" "app_ami" { name = "virtualization-type" values = ["hvm"] } - resource "aws_instance" "web" { +} + +resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id instance_type = "t3.nano" tags = { Name = "HelloWorld" } -} } \ No newline at end of file From 57b6a168407c1514b9727f02ee6038f657f951f7 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 23 Jun 2026 22:03:53 +0000 Subject: [PATCH 04/36] Added instance and location --- main.tf | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 98f8c7d008..88d8cb19f0 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,16 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 6.0" + } + } +} + +provider "aws" { + region = "us-west-2" +} + data "aws_ami" "app_ami" { most_recent = true owners = ["amazon"] @@ -25,9 +38,21 @@ data "aws_ami" "app_ami" { resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id - instance_type = "t3.nano" + instance_type = "t2.micro" tags = { Name = "HelloWorld" } +} + +output "instance_id" { + value = aws_instance.web.id +} + +output "public_ip" { + value = aws_instance.web.public_ip +} + +output "ami_id" { + value = data.aws_ami.app_ami.id } \ No newline at end of file From 5a3eafdc50a6318f7bd1f3a610719617e8c50656 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 23 Jun 2026 22:07:00 +0000 Subject: [PATCH 05/36] Added --- main.tf | 25 ------------------------- providers.tf | 5 +++-- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/main.tf b/main.tf index 88d8cb19f0..89b19ac792 100644 --- a/main.tf +++ b/main.tf @@ -1,16 +1,3 @@ -terraform { - required_providers { - aws = { - source = "hashicorp/aws" - version = "~> 6.0" - } - } -} - -provider "aws" { - region = "us-west-2" -} - data "aws_ami" "app_ami" { most_recent = true owners = ["amazon"] @@ -43,16 +30,4 @@ resource "aws_instance" "web" { tags = { Name = "HelloWorld" } -} - -output "instance_id" { - value = aws_instance.web.id -} - -output "public_ip" { - value = aws_instance.web.public_ip -} - -output "ami_id" { - value = data.aws_ami.app_ami.id } \ No newline at end of file diff --git a/providers.tf b/providers.tf index c41e3650b5..c29947b37a 100644 --- a/providers.tf +++ b/providers.tf @@ -2,10 +2,11 @@ terraform { required_providers { aws = { source = "hashicorp/aws" + version = "~> 6.0" } } } provider "aws" { - region = "us-west-2" -} + region = "us-west-2" +} \ No newline at end of file From 1f06e2c1ad5fe57989179e2c3bd3104816191eb7 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 23 Jun 2026 22:15:42 +0000 Subject: [PATCH 06/36] added the instance type --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 89b19ac792..f24b5d1feb 100644 --- a/main.tf +++ b/main.tf @@ -25,7 +25,7 @@ data "aws_ami" "app_ami" { resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id - instance_type = "t2.micro" + instance_type = "t3.micro" tags = { Name = "HelloWorld" From 64eab00f2628f27c672e973fa630ec0ff970a21c Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Wed, 24 Jun 2026 02:14:09 +0000 Subject: [PATCH 07/36] initial commit --- outputs.tf | 12 ++++++------ variables.tf | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) 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..3f73ef7884 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 = variable.instance_type +} From 2f05519d0d763bf867abd7ac7eff7e25725ba641 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Wed, 24 Jun 2026 02:17:54 +0000 Subject: [PATCH 08/36] updated instace type --- main.tf | 2 +- variables.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index f24b5d1feb..134ab36b7f 100644 --- a/main.tf +++ b/main.tf @@ -25,7 +25,7 @@ data "aws_ami" "app_ami" { resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id - instance_type = "t3.micro" + instance_type = var.instance_type tags = { Name = "HelloWorld" diff --git a/variables.tf b/variables.tf index 3f73ef7884..60856bc925 100644 --- a/variables.tf +++ b/variables.tf @@ -1,4 +1,4 @@ variable "instance_type" { description = "Type of EC2 instance to provision" - default = variable.instance_type + default = "t3.nano" } From b83aa2444af1457cfd50da92a1b1173c8f94bc3e Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Wed, 24 Jun 2026 02:23:53 +0000 Subject: [PATCH 09/36] change instace type --- variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variables.tf b/variables.tf index 60856bc925..b6cca62204 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" +} \ No newline at end of file From 4367076bc380ff98412ac95aa42125a20272751c Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Wed, 24 Jun 2026 02:31:04 +0000 Subject: [PATCH 10/36] Updated --- main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/main.tf b/main.tf index 134ab36b7f..240811c2ec 100644 --- a/main.tf +++ b/main.tf @@ -22,7 +22,6 @@ data "aws_ami" "app_ami" { values = ["hvm"] } } - resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type From 93b458b03a8eb225166b0fa9ff2733cb100e91c2 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Wed, 24 Jun 2026 03:13:25 +0000 Subject: [PATCH 11/36] changed the variable --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index b6cca62204..91e5faf825 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" } \ No newline at end of file From 92acf9344e916d6cf7c95c3aeae6958525c3803a Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Wed, 24 Jun 2026 13:41:37 +0000 Subject: [PATCH 12/36] updated the outputs --- outputs.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 83af5f75229ace0d7a40622e88955b96c16d9261 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Wed, 24 Jun 2026 13:46:37 +0000 Subject: [PATCH 13/36] same update the output file --- outputs.tf | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/outputs.tf b/outputs.tf index 7e9410b55c..a06657cb13 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,7 +1,19 @@ output "instance_ami" { - value = aws_instance.blog.ami + value = aws_instance.web.ami } output "instance_arn" { - value = aws_instance.blog.arn + value = aws_instance.web.arn } + +output "public_ip" { + value = aws_instance.web.public_ip +} + +output "public_dns" { + value = aws_instance.web.public_dns +} + +output "instance_id" { + value = aws_instance.web.id +} \ No newline at end of file From 90bf0ca6982e8b94cc9501d004be241e49c8aacb Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Wed, 24 Jun 2026 14:33:59 +0000 Subject: [PATCH 14/36] created securoty group --- main.tf | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/main.tf b/main.tf index 240811c2ec..1c23b58693 100644 --- a/main.tf +++ b/main.tf @@ -21,12 +21,54 @@ data "aws_ami" "app_ami" { name = "virtualization-type" values = ["hvm"] } + data"aws_vpc" "default" { + default = true + } } resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type +vpc_security_group_ids =[aws_security_group_web_id] tags = { Name = "HelloWorld" } +} +resource "aws_security_group" "web" { + name = "web" + description = "allow http and https in. Allow everything out" + + vpc_id = data.aws_vpc.default.id +} +resource "aws_security_group_rule" "web_http_in" { + type = "ingress" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_block =["0.0.0.0/0"] + + aws_security_group_id = aws_security_group_web_id + +} + +resource "aws_security_group_rule" "web_https_in" { + type = "ingress" + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_block =["0.0.0.0/0"] + + aws_security_group_id = aws_security_group_web_id + +} + +resource "aws_security_group_rule" "web_everything_out" { + type = "egress" + from_port = 0 + to_port = 0 + protocol = "-" + cidr_block =["0.0.0.0/0"] + + aws_security_group_id = aws_security_group_web_id + } \ No newline at end of file From 56df90c3e06ff2d03ed4759c322837f1ef925982 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Wed, 24 Jun 2026 14:36:52 +0000 Subject: [PATCH 15/36] fix the error --- main.tf | 71 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/main.tf b/main.tf index 1c23b58693..4c4bcbe5cd 100644 --- a/main.tf +++ b/main.tf @@ -21,54 +21,55 @@ data "aws_ami" "app_ami" { name = "virtualization-type" values = ["hvm"] } - data"aws_vpc" "default" { - default = true - } } -resource "aws_instance" "web" { - ami = data.aws_ami.app_ami.id - instance_type = var.instance_type -vpc_security_group_ids =[aws_security_group_web_id] - tags = { - Name = "HelloWorld" - } +data "aws_vpc" "default" { + default = true } + resource "aws_security_group" "web" { - name = "web" - description = "allow http and https in. Allow everything out" + name = "web-sg" + description = "Allow HTTP and HTTPS inbound and all outbound" + vpc_id = data.aws_vpc.default.id - vpc_id = data.aws_vpc.default.id + tags = { + Name = "web-sg" + } } -resource "aws_security_group_rule" "web_http_in" { - type = "ingress" - from_port = 80 - to_port = 80 - protocol = "tcp" - cidr_block =["0.0.0.0/0"] - - aws_security_group_id = aws_security_group_web_id +resource "aws_security_group_rule" "web_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.web.id } resource "aws_security_group_rule" "web_https_in" { - type = "ingress" - from_port = 443 - to_port = 443 - protocol = "tcp" - cidr_block =["0.0.0.0/0"] - - aws_security_group_id = aws_security_group_web_id - + type = "ingress" + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + security_group_id = aws_security_group.web.id } resource "aws_security_group_rule" "web_everything_out" { - type = "egress" - from_port = 0 - to_port = 0 - protocol = "-" - cidr_block =["0.0.0.0/0"] + type = "egress" + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + security_group_id = aws_security_group.web.id +} - aws_security_group_id = aws_security_group_web_id +resource "aws_instance" "web" { + ami = data.aws_ami.app_ami.id + instance_type = var.instance_type + vpc_security_group_ids = [aws_security_group.web.id] + tags = { + Name = "HelloWorld" + } } \ No newline at end of file From 46329131d33fcb8e48d1420151ad793ae092b6e3 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Wed, 24 Jun 2026 20:20:12 +0000 Subject: [PATCH 16/36] use module for security group --- main.tf | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/main.tf b/main.tf index 4c4bcbe5cd..c4a33a0a33 100644 --- a/main.tf +++ b/main.tf @@ -27,47 +27,29 @@ data "aws_vpc" "default" { default = true } -resource "aws_security_group" "web" { - name = "web-sg" +module "web_sg" { + source = "terraform-aws-modules/security-group/aws" + version = "6.0.0" + + name = "web-new-sg" description = "Allow HTTP and HTTPS inbound and all outbound" vpc_id = data.aws_vpc.default.id - tags = { - Name = "web-sg" - } -} + ingress_rules = ["http-80-tcp", "https-443-tcp"] + ingress_cidr_blocks = ["0.0.0.0/0"] -resource "aws_security_group_rule" "web_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.web.id -} + egress_rules = ["all-all"] + egress_cidr_blocks = ["0.0.0.0/0"] -resource "aws_security_group_rule" "web_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.web.id -} - -resource "aws_security_group_rule" "web_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.web.id + tags = { + Name = "web-new-sg" + } } resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type - vpc_security_group_ids = [aws_security_group.web.id] + vpc_security_group_ids = [module.web_sg.security_group_id] tags = { Name = "HelloWorld" From 0e53415a595e14f33d2534a8e21d0da262d5758b Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Wed, 24 Jun 2026 20:23:07 +0000 Subject: [PATCH 17/36] update the modules --- main.tf | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/main.tf b/main.tf index c4a33a0a33..1c88160980 100644 --- a/main.tf +++ b/main.tf @@ -35,11 +35,31 @@ module "web_sg" { description = "Allow HTTP and HTTPS inbound and all outbound" vpc_id = data.aws_vpc.default.id - ingress_rules = ["http-80-tcp", "https-443-tcp"] - ingress_cidr_blocks = ["0.0.0.0/0"] + ingress_rules = { + http = { + from_port = 80 + to_port = 80 + ip_protocol = "tcp" + cidr_ipv4 = "0.0.0.0/0" + description = "Allow HTTP" + } - egress_rules = ["all-all"] - egress_cidr_blocks = ["0.0.0.0/0"] + https = { + from_port = 443 + to_port = 443 + ip_protocol = "tcp" + cidr_ipv4 = "0.0.0.0/0" + description = "Allow HTTPS" + } + } + + egress_rules = { + all = { + ip_protocol = "-1" + cidr_ipv4 = "0.0.0.0/0" + description = "Allow all outbound" + } + } tags = { Name = "web-new-sg" @@ -49,7 +69,7 @@ module "web_sg" { resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type - vpc_security_group_ids = [module.web_sg.security_group_id] + vpc_security_group_ids = [module.web_sg.id] tags = { Name = "HelloWorld" From 1ed89cd682af0f0e40964d58da36a4ecae0f5291 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Wed, 24 Jun 2026 20:36:50 +0000 Subject: [PATCH 18/36] removed the security group --- main.tf | 48 ++---------------------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/main.tf b/main.tf index 1c88160980..134ab36b7f 100644 --- a/main.tf +++ b/main.tf @@ -23,53 +23,9 @@ data "aws_ami" "app_ami" { } } -data "aws_vpc" "default" { - default = true -} - -module "web_sg" { - source = "terraform-aws-modules/security-group/aws" - version = "6.0.0" - - name = "web-new-sg" - description = "Allow HTTP and HTTPS inbound and all outbound" - vpc_id = data.aws_vpc.default.id - - ingress_rules = { - http = { - from_port = 80 - to_port = 80 - ip_protocol = "tcp" - cidr_ipv4 = "0.0.0.0/0" - description = "Allow HTTP" - } - - https = { - from_port = 443 - to_port = 443 - ip_protocol = "tcp" - cidr_ipv4 = "0.0.0.0/0" - description = "Allow HTTPS" - } - } - - egress_rules = { - all = { - ip_protocol = "-1" - cidr_ipv4 = "0.0.0.0/0" - description = "Allow all outbound" - } - } - - tags = { - Name = "web-new-sg" - } -} - resource "aws_instance" "web" { - ami = data.aws_ami.app_ami.id - instance_type = var.instance_type - vpc_security_group_ids = [module.web_sg.id] + ami = data.aws_ami.app_ami.id + instance_type = var.instance_type tags = { Name = "HelloWorld" From 2355d94e76c954e09b2538de4bdf0b8892a8b886 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Thu, 25 Jun 2026 15:34:39 +0000 Subject: [PATCH 19/36] Added the module VPC --- main.tf | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 134ab36b7f..22bb50f78f 100644 --- a/main.tf +++ b/main.tf @@ -22,10 +22,30 @@ data "aws_ami" "app_ami" { values = ["hvm"] } } + module "web_vpc" { + source = "terraform-aws-modules/vpc/aws" + version = "~> 6.0" + name = "mydev" + cidr = "10.0.0.0/16" + + azs = ["us-west-2a", "us-west-2b", "us-west-2c"] + 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 = false + enable_vpn_gateway = false + + tags = { + Terraform = "true" + Environment = "dev" + } +} resource "aws_instance" "web" { - ami = data.aws_ami.app_ami.id - instance_type = var.instance_type + ami = data.aws_ami.app_ami.id + instance_type = var.instance_type + subnet_id = module.vpc.public_subnets[0] + associate_public_ip_address = true tags = { Name = "HelloWorld" From 35431ef480ebd398e8562f050933b4dff9159bc9 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Thu, 25 Jun 2026 15:36:03 +0000 Subject: [PATCH 20/36] error fixed --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 22bb50f78f..78e1c5817e 100644 --- a/main.tf +++ b/main.tf @@ -44,7 +44,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.vpc.public_subnets[0] + subnet_id = module.web_vpc.public_subnets[0] associate_public_ip_address = true tags = { From e3aafe579c49c00e6915fc11906a1515daa927db Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Mon, 29 Jun 2026 14:23:15 +0000 Subject: [PATCH 21/36] load balancer --- main.tf | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 78e1c5817e..a3b4b7ad4e 100644 --- a/main.tf +++ b/main.tf @@ -22,7 +22,8 @@ data "aws_ami" "app_ami" { values = ["hvm"] } } - module "web_vpc" { + +module "web_vpc" { source = "terraform-aws-modules/vpc/aws" version = "~> 6.0" @@ -41,13 +42,95 @@ data "aws_ami" "app_ami" { Environment = "dev" } } + +resource "aws_security_group" "web_instance_sg" { + name = "web-instance-sg" +} + resource "aws_instance" "web" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type subnet_id = module.web_vpc.public_subnets[0] associate_public_ip_address = true + vpc_security_group_ids = [aws_security_group.web_instance_sg.id] + + user_data = <<-EOF +#!/bin/bash +dnf update -y +dnf install -y httpd +systemctl start httpd +systemctl enable httpd +echo "Hello from Terraform EC2 behind ALB" > /var/www/html/index.html +EOF tags = { Name = "HelloWorld" } +} + +module "alb" { + source = "terraform-aws-modules/alb/aws" + version = "~> 9.0" + + name = "my-alb" + load_balancer_type = "application" + + vpc_id = module.web_vpc.vpc_id + subnets = module.web_vpc.public_subnets + + security_group_ingress_rules = { + all_http = { + from_port = 80 + to_port = 80 + ip_protocol = "tcp" + description = "Allow HTTP web traffic" + cidr_ipv4 = "0.0.0.0/0" + } + } + + security_group_egress_rules = { + all = { + ip_protocol = "-1" + cidr_ipv4 = "0.0.0.0/0" + } + } + + listeners = { + web-http = { + port = 80 + protocol = "HTTP" + + forward = { + target_group_arn = "aws_lb_target_group_web.arn" + } + } + } + + target_groups = { + web-instance = { + name_prefix = "web" + protocol = "HTTP" + port = 80 + target_type = "instance" + target_id = aws_instance.web.id + } + } + + resource "aws_lb_target_group" "web" { + name = "web" + port = 80 + protocol = "HTTP" + vpc_id = module_web_vpc.vpc_id +} + +resource "aws_lb_target_group_attachment" "web" { + target_group_arn = aws_lb_target_group.web.arn + target_id = aws_instance.web.id + port = 80 +} + + tags = { + Environment = "dev" + Project = "Terraform-Learning" + } } \ No newline at end of file From ffb6a5d03763295ec8b3bdaa654ad2f5e6e49892 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Mon, 29 Jun 2026 14:25:20 +0000 Subject: [PATCH 22/36] resloved --- main.tf | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/main.tf b/main.tf index a3b4b7ad4e..b41757a29d 100644 --- a/main.tf +++ b/main.tf @@ -45,6 +45,28 @@ module "web_vpc" { resource "aws_security_group" "web_instance_sg" { name = "web-instance-sg" + description = "Allow HTTP traffic to EC2" + vpc_id = module.web_vpc.vpc_id + + ingress { + description = "Allow HTTP from ALB/internet" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + description = "Allow all outbound traffic" + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "web-instance-sg" + } } resource "aws_instance" "web" { @@ -96,12 +118,12 @@ module "alb" { } listeners = { - web-http = { + http = { port = 80 protocol = "HTTP" forward = { - target_group_arn = "aws_lb_target_group_web.arn" + target_group_key = "web-instance" } } } @@ -116,19 +138,6 @@ module "alb" { } } - resource "aws_lb_target_group" "web" { - name = "web" - port = 80 - protocol = "HTTP" - vpc_id = module_web_vpc.vpc_id -} - -resource "aws_lb_target_group_attachment" "web" { - target_group_arn = aws_lb_target_group.web.arn - target_id = aws_instance.web.id - port = 80 -} - tags = { Environment = "dev" Project = "Terraform-Learning" From 957e2a77a88f27b79927c868e395aeff023e53e9 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Mon, 29 Jun 2026 14:49:25 +0000 Subject: [PATCH 23/36] fix EC2 security --- main.tf | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/main.tf b/main.tf index b41757a29d..cbf9c287ec 100644 --- a/main.tf +++ b/main.tf @@ -45,15 +45,15 @@ module "web_vpc" { resource "aws_security_group" "web_instance_sg" { name = "web-instance-sg" - description = "Allow HTTP traffic to EC2" + description = "Allow HTTP from ALB" vpc_id = module.web_vpc.vpc_id ingress { - description = "Allow HTTP from ALB/internet" - from_port = 80 - to_port = 80 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] + description = "Allow HTTP from ALB" + from_port = 80 + to_port = 80 + protocol = "tcp" + security_groups = [module.alb.security_group_id] } egress { @@ -76,6 +76,8 @@ resource "aws_instance" "web" { associate_public_ip_address = true vpc_security_group_ids = [aws_security_group.web_instance_sg.id] + user_data_replace_on_change = true + user_data = <<-EOF #!/bin/bash dnf update -y From 3be533a7a2d819051ca1f72d325a8d9cd289e5c9 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Mon, 29 Jun 2026 18:58:00 +0000 Subject: [PATCH 24/36] Allow traffic to EC2 --- main.tf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.tf b/main.tf index cbf9c287ec..396e8e7525 100644 --- a/main.tf +++ b/main.tf @@ -44,16 +44,16 @@ module "web_vpc" { } resource "aws_security_group" "web_instance_sg" { - name = "web-instance-sg" - description = "Allow HTTP from ALB" + name_prefix = "web-instance-sg-" + description = "Allow HTTP traffic to EC2" vpc_id = module.web_vpc.vpc_id ingress { - description = "Allow HTTP from ALB" - from_port = 80 - to_port = 80 - protocol = "tcp" - security_groups = [module.alb.security_group_id] + description = "Allow HTTP" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] } egress { From 1eac315b0aa426283086d8006b43d6ddc06701f2 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Mon, 29 Jun 2026 19:21:35 +0000 Subject: [PATCH 25/36] autoscaling --- main.tf | 142 +++++++++++++++++++++++++++++++++-------------------- outputs.tf | 19 ------- 2 files changed, 88 insertions(+), 73 deletions(-) diff --git a/main.tf b/main.tf index 396e8e7525..1f77957eec 100644 --- a/main.tf +++ b/main.tf @@ -43,55 +43,6 @@ module "web_vpc" { } } -resource "aws_security_group" "web_instance_sg" { - name_prefix = "web-instance-sg-" - description = "Allow HTTP traffic to EC2" - vpc_id = module.web_vpc.vpc_id - - ingress { - description = "Allow HTTP" - from_port = 80 - to_port = 80 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } - - egress { - description = "Allow all outbound traffic" - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - } - - tags = { - Name = "web-instance-sg" - } -} - -resource "aws_instance" "web" { - ami = data.aws_ami.app_ami.id - instance_type = var.instance_type - subnet_id = module.web_vpc.public_subnets[0] - associate_public_ip_address = true - vpc_security_group_ids = [aws_security_group.web_instance_sg.id] - - user_data_replace_on_change = true - - user_data = <<-EOF -#!/bin/bash -dnf update -y -dnf install -y httpd -systemctl start httpd -systemctl enable httpd -echo "Hello from Terraform EC2 behind ALB" > /var/www/html/index.html -EOF - - tags = { - Name = "HelloWorld" - } -} - module "alb" { source = "terraform-aws-modules/alb/aws" version = "~> 9.0" @@ -132,11 +83,94 @@ module "alb" { target_groups = { web-instance = { - name_prefix = "web" - protocol = "HTTP" - port = 80 - target_type = "instance" - target_id = aws_instance.web.id + name_prefix = "web" + protocol = "HTTP" + port = 80 + target_type = "instance" + create_attachment = false + + health_check = { + enabled = true + path = "/" + port = "traffic-port" + healthy_threshold = 2 + unhealthy_threshold = 2 + timeout = 5 + interval = 30 + matcher = "200" + } + } + } + + tags = { + Environment = "dev" + Project = "Terraform-Learning" + } +} + +resource "aws_security_group" "web_instance_sg" { + name_prefix = "web-instance-sg-" + description = "Allow HTTP traffic from ALB to EC2" + vpc_id = module.web_vpc.vpc_id + + ingress { + description = "Allow HTTP from ALB" + from_port = 80 + to_port = 80 + protocol = "tcp" + security_groups = [module.alb.security_group_id] + } + + egress { + description = "Allow all outbound traffic" + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "web-instance-sg" + } +} + +module "autoscaling" { + source = "terraform-aws-modules/autoscaling/aws" + version = "9.2.1" + + name = "web-asg" + + min_size = 1 + max_size = 2 + desired_capacity = 1 + + vpc_zone_identifier = module.web_vpc.public_subnets + + health_check_type = "ELB" + health_check_grace_period = 300 + + launch_template_name = "web-asg-template" + launch_template_description = "Launch template for web ASG" + update_default_version = true + + image_id = data.aws_ami.app_ami.id + instance_type = var.instance_type + security_groups = [aws_security_group.web_instance_sg.id] + + user_data = base64encode(<<-EOF +#!/bin/bash +dnf update -y +dnf install -y httpd +systemctl start httpd +systemctl enable httpd +echo "Hello from Terraform Auto Scaling behind ALB" > /var/www/html/index.html +EOF + ) + + traffic_source_attachments = { + web_alb = { + traffic_source_identifier = module.alb.target_groups["web-instance"].arn + traffic_source_type = "elbv2" } } diff --git a/outputs.tf b/outputs.tf index a06657cb13..e69de29bb2 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,19 +0,0 @@ -output "instance_ami" { - value = aws_instance.web.ami -} - -output "instance_arn" { - value = aws_instance.web.arn -} - -output "public_ip" { - value = aws_instance.web.public_ip -} - -output "public_dns" { - value = aws_instance.web.public_dns -} - -output "instance_id" { - value = aws_instance.web.id -} \ No newline at end of file From 6ba23688c66be23c41de0e6767ce3c5a5c326116 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Mon, 29 Jun 2026 21:44:57 +0000 Subject: [PATCH 26/36] refractor to use variables --- main.tf | 38 +++++++++++++++++++++++++------------- variables.tf | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 13 deletions(-) diff --git a/main.tf b/main.tf index 1f77957eec..0db29f9645 100644 --- a/main.tf +++ b/main.tf @@ -1,10 +1,10 @@ data "aws_ami" "app_ami" { most_recent = true - owners = ["amazon"] + owners = var.ami_filter.owners filter { name = "name" - values = ["al2023-ami-2023.*-x86_64"] + values = [var.ami_filter.name] } filter { @@ -27,19 +27,31 @@ module "web_vpc" { source = "terraform-aws-modules/vpc/aws" version = "~> 6.0" - name = "mydev" - cidr = "10.0.0.0/16" + name = var.environment.name + cidr = "${var.environment.network_prefix}.0.0/16" - azs = ["us-west-2a", "us-west-2b", "us-west-2c"] - 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-west-2a", "us-west-2b", "us-west-2c"] + + private_subnets = [ + "${var.environment.network_prefix}.1.0/24", + "${var.environment.network_prefix}.2.0/24", + "${var.environment.network_prefix}.3.0/24" + ] + + public_subnets = [ + "${var.environment.network_prefix}.101.0/24", + "${var.environment.network_prefix}.102.0/24", + "${var.environment.network_prefix}.103.0/24" + ] + + map_public_ip_on_launch = true enable_nat_gateway = false enable_vpn_gateway = false tags = { Terraform = "true" - Environment = "dev" + Environment = var.environment.name } } @@ -103,7 +115,7 @@ module "alb" { } tags = { - Environment = "dev" + Environment = var.environment.name Project = "Terraform-Learning" } } @@ -140,9 +152,9 @@ module "autoscaling" { name = "web-asg" - min_size = 1 - max_size = 2 - desired_capacity = 1 + min_size = var.min_size + max_size = var.max_size + desired_capacity = var.desired_capacity vpc_zone_identifier = module.web_vpc.public_subnets @@ -175,7 +187,7 @@ EOF } tags = { - Environment = "dev" + Environment = var.environment.name Project = "Terraform-Learning" } } \ No newline at end of file diff --git a/variables.tf b/variables.tf index 91e5faf825..5fc51df5af 100644 --- a/variables.tf +++ b/variables.tf @@ -1,4 +1,49 @@ variable "instance_type" { description = "Type of EC2 instance to provision" + type = string default = "t3.micro" +} + +variable "ami_filter" { + description = "Name filter and owner for AMI" + type = object({ + name = string + owners = list(string) + }) + + default = { + name = "al2023-ami-2023.*-x86_64" + owners = ["amazon"] + } +} + +variable "environment" { + description = "Deployment environment details" + type = object({ + name = string + network_prefix = string + }) + + default = { + name = "dev" + network_prefix = "10.0" + } +} + +variable "min_size" { + description = "Minimum number of instances in the ASG" + type = number + default = 1 +} + +variable "max_size" { + description = "Maximum number of instances in the ASG" + type = number + default = 2 +} + +variable "desired_capacity" { + description = "Desired number of instances in the ASG" + type = number + default = 1 } \ No newline at end of file From f625a4ecbedd15693d928635f5ae168d91c0d11b Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 30 Jun 2026 19:32:18 +0000 Subject: [PATCH 27/36] deploy dev env --- envirnoments/dev/main.tf | 4 +++ envirnoments/dev/moved.tf | 26 +++++++++++++++++++ providers.tf => envirnoments/dev/providers.tf | 0 modules/outputs.tf | 4 +++ variables.tf => modules/variables.tf | 0 main.tf => modules/web/main.tf | 0 outputs.tf | 0 7 files changed, 34 insertions(+) create mode 100644 envirnoments/dev/main.tf create mode 100644 envirnoments/dev/moved.tf rename providers.tf => envirnoments/dev/providers.tf (100%) create mode 100644 modules/outputs.tf rename variables.tf => modules/variables.tf (100%) rename main.tf => modules/web/main.tf (100%) delete mode 100644 outputs.tf diff --git a/envirnoments/dev/main.tf b/envirnoments/dev/main.tf new file mode 100644 index 0000000000..2fc45421ab --- /dev/null +++ b/envirnoments/dev/main.tf @@ -0,0 +1,4 @@ +moduel "dev" { + source = "../../modules/blog" +} + \ No newline at end of file diff --git a/envirnoments/dev/moved.tf b/envirnoments/dev/moved.tf new file mode 100644 index 0000000000..5fb8898abd --- /dev/null +++ b/envirnoments/dev/moved.tf @@ -0,0 +1,26 @@ +moved { + from = module.web_vpc + to = module.dev.module.web_vpc +} + +moved { + from = module.web_sg + to = module.dev.module.web_sg +} + +moved { + from = aws_security_group_web" + to = module.dev.aws_security_group.web +} + +moved { + from = module.web_alb + to = module.dev.module.web_alb +} + +moved { + from = module.web_autoscaling + to = module.dev.module.web_autoscaling +} + + \ No newline at end of file diff --git a/providers.tf b/envirnoments/dev/providers.tf similarity index 100% rename from providers.tf rename to envirnoments/dev/providers.tf diff --git a/modules/outputs.tf b/modules/outputs.tf new file mode 100644 index 0000000000..88ac8cf548 --- /dev/null +++ b/modules/outputs.tf @@ -0,0 +1,4 @@ +output "environment_url"{ + value = module.web_alb.dns_name +} + \ No newline at end of file diff --git a/variables.tf b/modules/variables.tf similarity index 100% rename from variables.tf rename to modules/variables.tf diff --git a/main.tf b/modules/web/main.tf similarity index 100% rename from main.tf rename to modules/web/main.tf diff --git a/outputs.tf b/outputs.tf deleted file mode 100644 index e69de29bb2..0000000000 From 01690ecbbe138014445613999ab139a1d0019cb5 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 30 Jun 2026 19:35:58 +0000 Subject: [PATCH 28/36] updated --- envirnoments/dev/main.tf | 2 +- modules/{web => }/main.tf | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename modules/{web => }/main.tf (100%) diff --git a/envirnoments/dev/main.tf b/envirnoments/dev/main.tf index 2fc45421ab..3b5263cbbc 100644 --- a/envirnoments/dev/main.tf +++ b/envirnoments/dev/main.tf @@ -1,4 +1,4 @@ -moduel "dev" { +module "dev" { source = "../../modules/blog" } \ No newline at end of file diff --git a/modules/web/main.tf b/modules/main.tf similarity index 100% rename from modules/web/main.tf rename to modules/main.tf From 69408b1b672c0aec271616b998bc0a9f2119ac97 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 30 Jun 2026 19:38:57 +0000 Subject: [PATCH 29/36] redeployed --- envirnoments/dev/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/envirnoments/dev/main.tf b/envirnoments/dev/main.tf index 3b5263cbbc..ce6158c8ef 100644 --- a/envirnoments/dev/main.tf +++ b/envirnoments/dev/main.tf @@ -1,4 +1,4 @@ module "dev" { - source = "../../modules/blog" + source = "../../modules" } \ No newline at end of file From 0667bf8f04ba0ab4145f7c122971e985235cd186 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 30 Jun 2026 19:47:56 +0000 Subject: [PATCH 30/36] updated --- {envirnoments => enviroments}/dev/main.tf | 0 {envirnoments => enviroments}/dev/moved.tf | 0 {envirnoments => enviroments}/dev/providers.tf | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {envirnoments => enviroments}/dev/main.tf (100%) rename {envirnoments => enviroments}/dev/moved.tf (100%) rename {envirnoments => enviroments}/dev/providers.tf (100%) diff --git a/envirnoments/dev/main.tf b/enviroments/dev/main.tf similarity index 100% rename from envirnoments/dev/main.tf rename to enviroments/dev/main.tf diff --git a/envirnoments/dev/moved.tf b/enviroments/dev/moved.tf similarity index 100% rename from envirnoments/dev/moved.tf rename to enviroments/dev/moved.tf diff --git a/envirnoments/dev/providers.tf b/enviroments/dev/providers.tf similarity index 100% rename from envirnoments/dev/providers.tf rename to enviroments/dev/providers.tf From 4fa240a93db26cbf914ae8e24fe2e5f52be58f0c Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 30 Jun 2026 19:52:29 +0000 Subject: [PATCH 31/36] updated --- enviroments/dev/moved.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/enviroments/dev/moved.tf b/enviroments/dev/moved.tf index 5fb8898abd..897a381d57 100644 --- a/enviroments/dev/moved.tf +++ b/enviroments/dev/moved.tf @@ -9,8 +9,8 @@ moved { } moved { - from = aws_security_group_web" - to = module.dev.aws_security_group.web + from = aws_security_group.web_instance_sg + to = module.dev.aws_security_group.web_instance_sg } moved { From 4e99fea2ae0e2921d1185ae0819e36eb85c46dd8 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 30 Jun 2026 19:55:54 +0000 Subject: [PATCH 32/36] uodated --- enviroments/dev/moved.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/enviroments/dev/moved.tf b/enviroments/dev/moved.tf index 897a381d57..7400e087e9 100644 --- a/enviroments/dev/moved.tf +++ b/enviroments/dev/moved.tf @@ -1,6 +1,6 @@ moved { - from = module.web_vpc - to = module.dev.module.web_vpc + from = module.web_vpc + to = module.dev.module.web_vpc } moved { @@ -14,13 +14,13 @@ moved { } moved { - from = module.web_alb - to = module.dev.module.web_alb + from = module.alb + to = module.dev.module.alb } moved { - from = module.web_autoscaling - to = module.dev.module.web_autoscaling + from = module.autoscaling + to = module.dev.module.autoscaling } \ No newline at end of file From f7447dc3c4c044a4cb79215a1016762b01f4695d Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 30 Jun 2026 19:57:19 +0000 Subject: [PATCH 33/36] updated --- enviroments/dev/moved.tf | 9 +-------- modules/outputs.tf | 13 ++++++++++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/enviroments/dev/moved.tf b/enviroments/dev/moved.tf index 7400e087e9..64b4232025 100644 --- a/enviroments/dev/moved.tf +++ b/enviroments/dev/moved.tf @@ -3,11 +3,6 @@ moved { to = module.dev.module.web_vpc } -moved { - from = module.web_sg - to = module.dev.module.web_sg -} - moved { from = aws_security_group.web_instance_sg to = module.dev.aws_security_group.web_instance_sg @@ -21,6 +16,4 @@ moved { moved { from = module.autoscaling to = module.dev.module.autoscaling -} - - \ No newline at end of file +} \ No newline at end of file diff --git a/modules/outputs.tf b/modules/outputs.tf index 88ac8cf548..1f129c19fa 100644 --- a/modules/outputs.tf +++ b/modules/outputs.tf @@ -1,4 +1,11 @@ -output "environment_url"{ - value = module.web_alb.dns_name +output "environment_url" { + value = module.alb.dns_name } - \ No newline at end of file + +output "vpc_id" { + value = module.web_vpc.vpc_id +} + +output "autoscaling_group_name" { + value = module.autoscaling.autoscaling_group_name +} \ No newline at end of file From 8a0df5625647edfd05cf50ba7b2609aa82873fc0 Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 30 Jun 2026 19:58:56 +0000 Subject: [PATCH 34/36] cleanup --- enviroments/dev/moved.tf | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 enviroments/dev/moved.tf diff --git a/enviroments/dev/moved.tf b/enviroments/dev/moved.tf deleted file mode 100644 index 64b4232025..0000000000 --- a/enviroments/dev/moved.tf +++ /dev/null @@ -1,19 +0,0 @@ -moved { - from = module.web_vpc - to = module.dev.module.web_vpc -} - -moved { - from = aws_security_group.web_instance_sg - to = module.dev.aws_security_group.web_instance_sg -} - -moved { - from = module.alb - to = module.dev.module.alb -} - -moved { - from = module.autoscaling - to = module.dev.module.autoscaling -} \ No newline at end of file From 2388647e484ca5e5d8a0cb4e734cf0ae6d20ae3a Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 30 Jun 2026 20:36:52 +0000 Subject: [PATCH 35/36] deploy qa --- enviroments/qa/main.tf | 13 +++++++++++++ enviroments/qa/outputs.tf | 3 +++ enviroments/qa/providers.tf | 12 ++++++++++++ modules/main.tf | 10 +++++----- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 enviroments/qa/main.tf create mode 100644 enviroments/qa/outputs.tf create mode 100644 enviroments/qa/providers.tf diff --git a/enviroments/qa/main.tf b/enviroments/qa/main.tf new file mode 100644 index 0000000000..2a79e66470 --- /dev/null +++ b/enviroments/qa/main.tf @@ -0,0 +1,13 @@ +module "qa" { + source = "../../modules/web" + + environment = { + name = qa + network_prefix = "10.1" + + } + + min_size = 1 + max_size = 1 +} + \ No newline at end of file diff --git a/enviroments/qa/outputs.tf b/enviroments/qa/outputs.tf new file mode 100644 index 0000000000..7c89c90dc1 --- /dev/null +++ b/enviroments/qa/outputs.tf @@ -0,0 +1,3 @@ +output "environment_url" { + value = module.qa.environment_url +} \ No newline at end of file diff --git a/enviroments/qa/providers.tf b/enviroments/qa/providers.tf new file mode 100644 index 0000000000..c29947b37a --- /dev/null +++ b/enviroments/qa/providers.tf @@ -0,0 +1,12 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 6.0" + } + } +} + +provider "aws" { + region = "us-west-2" +} \ No newline at end of file diff --git a/modules/main.tf b/modules/main.tf index 0db29f9645..7b057a47e5 100644 --- a/modules/main.tf +++ b/modules/main.tf @@ -27,7 +27,7 @@ module "web_vpc" { source = "terraform-aws-modules/vpc/aws" version = "~> 6.0" - name = var.environment.name + name = ${var.environment.name}-web_vpc cidr = "${var.environment.network_prefix}.0.0/16" azs = ["us-west-2a", "us-west-2b", "us-west-2c"] @@ -59,7 +59,7 @@ module "alb" { source = "terraform-aws-modules/alb/aws" version = "~> 9.0" - name = "my-alb" + name = "${var.environment.name}-web-alb" load_balancer_type = "application" vpc_id = module.web_vpc.vpc_id @@ -142,7 +142,7 @@ resource "aws_security_group" "web_instance_sg" { } tags = { - Name = "web-instance-sg" + Name = "${var.environment.name}-web-instance-sg" } } @@ -150,7 +150,7 @@ module "autoscaling" { source = "terraform-aws-modules/autoscaling/aws" version = "9.2.1" - name = "web-asg" + name = "${var.environment.name}-web-asg" min_size = var.min_size max_size = var.max_size @@ -180,7 +180,7 @@ EOF ) traffic_source_attachments = { - web_alb = { + ${var.environment.name}-web_alb = { traffic_source_identifier = module.alb.target_groups["web-instance"].arn traffic_source_type = "elbv2" } From 779024e8511ac284b9915d94e67eb8aa8086321e Mon Sep 17 00:00:00 2001 From: ranjithk9812-code Date: Tue, 30 Jun 2026 20:43:26 +0000 Subject: [PATCH 36/36] typo mistakes --- modules/main.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/main.tf b/modules/main.tf index 7b057a47e5..15fb29c4a4 100644 --- a/modules/main.tf +++ b/modules/main.tf @@ -27,7 +27,7 @@ module "web_vpc" { source = "terraform-aws-modules/vpc/aws" version = "~> 6.0" - name = ${var.environment.name}-web_vpc + name = "${var.environment.name}-web-vpc" cidr = "${var.environment.network_prefix}.0.0/16" azs = ["us-west-2a", "us-west-2b", "us-west-2c"] @@ -179,12 +179,12 @@ echo "Hello from Terraform Auto Scaling behind ALB" > /var/www/html/index.html EOF ) - traffic_source_attachments = { - ${var.environment.name}-web_alb = { - traffic_source_identifier = module.alb.target_groups["web-instance"].arn - traffic_source_type = "elbv2" - } +traffic_source_attachments = { + web_alb = { + traffic_source_identifier = module.alb.target_groups["web-instance"].arn + traffic_source_type = "elbv2" } +} tags = { Environment = var.environment.name