From 98455a9e7020eb7fcce2a2592720eb997a9be2fc Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 20:02:35 +0100 Subject: [PATCH 01/89] 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..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 = "t3.nano" + instance_type = var.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 fc6017ee4143d4c0b28ec95d88238a4025ae1a84 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 20:06:51 +0100 Subject: [PATCH 02/89] Update main.tf --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 0bfc354510..a5284ea024 100644 --- a/main.tf +++ b/main.tf @@ -14,7 +14,7 @@ data "aws_ami" "app_ami" { owners = ["979382823631"] # Bitnami } -resource "aws_instance" "web" { +resource "aws_instance" "blog" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type From 977a98b74ddd473b14ba6cff4c9982e3dada6cc2 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 20:08:10 +0100 Subject: [PATCH 03/89] Update outputs.tf --- outputs.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outputs.tf b/outputs.tf index c429b19b48..fcd5c2a650 100644 --- a/outputs.tf +++ b/outputs.tf @@ -3,5 +3,5 @@ output "instance_ami" { } output "instance_arn" { - value = aws_instance.web.arn + value = aws_instance.blog.arn } From ae95d6a69cac95b141ebdb65009254be8a31b0e0 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 20:08:40 +0100 Subject: [PATCH 04/89] Update outputs.tf --- outputs.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outputs.tf b/outputs.tf index fcd5c2a650..7e9410b55c 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,5 +1,5 @@ output "instance_ami" { - value = aws_instance.web.ami + value = aws_instance.blog.ami } output "instance_arn" { From 190463646de619548265db412597fc95552a7b09 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 20:31:12 +0100 Subject: [PATCH 05/89] Create Security Group --- main.tf | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/main.tf b/main.tf index a5284ea024..e2c71bdf16 100644 --- a/main.tf +++ b/main.tf @@ -14,11 +14,40 @@ data "aws_ami" "app_ami" { owners = ["979382823631"] # Bitnami } +data "aws_vpc" "default"{ + default = true +} + resource "aws_instance" "blog" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type + vpc_security_groups_ids = [aws.aws_security_group.blog.id] + tags = { Name = "HelloWorld" } } + +resource "aws_security_group" "blog" { + name = "blog" + description = "Allow http(s) in, allow everthing out" + + 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] +} + +resource "aws_security_group_rule" "blog_all_out" { + type = "ingress" + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = [0.0.0.0/0] +} From 8e12a83a4925d7ba238a34358eb0373118fb0d82 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 20:33:21 +0100 Subject: [PATCH 06/89] Fixes CIDR for security rules --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index e2c71bdf16..35c09bd7a7 100644 --- a/main.tf +++ b/main.tf @@ -41,7 +41,7 @@ resource "aws_security_group_rule" "blog_http_in" { from_port = 80 to_port = 80 protocol = "tcp" - cidr_blocks = [0.0.0.0/0] + cidr_blocks = ["0.0.0.0/0"] } resource "aws_security_group_rule" "blog_all_out" { @@ -49,5 +49,5 @@ resource "aws_security_group_rule" "blog_all_out" { from_port = 0 to_port = 0 protocol = "-1" - cidr_blocks = [0.0.0.0/0] + cidr_blocks = ["0.0.0.0/0"] } From 764eaa6f8db50d7b76311a461a04e67692b6d6bc Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 20:34:49 +0100 Subject: [PATCH 07/89] fixed vpc_security_group_ids --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 35c09bd7a7..58d6c26abd 100644 --- a/main.tf +++ b/main.tf @@ -22,7 +22,7 @@ resource "aws_instance" "blog" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type - vpc_security_groups_ids = [aws.aws_security_group.blog.id] + vpc_security_group_ids = [aws.aws_security_group.blog.id] tags = { Name = "HelloWorld" From de01913dcc5f5fd7cef45ca47347035bbe1d7cfb Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 20:37:01 +0100 Subject: [PATCH 08/89] fixed aws_security_group.blog.id --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 58d6c26abd..97929a1de5 100644 --- a/main.tf +++ b/main.tf @@ -22,7 +22,7 @@ resource "aws_instance" "blog" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type - vpc_security_group_ids = [aws.aws_security_group.blog.id] + vpc_security_group_ids = [aws_security_group.blog.id] tags = { Name = "HelloWorld" @@ -45,7 +45,7 @@ resource "aws_security_group_rule" "blog_http_in" { } resource "aws_security_group_rule" "blog_all_out" { - type = "ingress" + type = "egress" from_port = 0 to_port = 0 protocol = "-1" From 608fa24f97ae20e8e35b155fbaafd365668e080c Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 20:43:11 +0100 Subject: [PATCH 09/89] fixed security group id for rules --- main.tf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.tf b/main.tf index 97929a1de5..a256375e90 100644 --- a/main.tf +++ b/main.tf @@ -42,6 +42,8 @@ resource "aws_security_group_rule" "blog_http_in" { 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_all_out" { @@ -50,4 +52,6 @@ resource "aws_security_group_rule" "blog_all_out" { to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] + + security_group_id = aws_security_group.blog.id } From 5876dc14184fe228dd88216dc9a4cf4cd45b2580 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 21:07:53 +0100 Subject: [PATCH 10/89] new security group using module --- main.tf | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index a256375e90..cad2d347f4 100644 --- a/main.tf +++ b/main.tf @@ -22,13 +22,27 @@ resource "aws_instance" "blog" { 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" + Name = "Learning Terraform" } } +module "blog_sg" { + source = "terraform-aws-modules/security-group/aws" + version = "5.3.0" + name = "blog_new" + + vpc_id = data.aws_vpc.default.id + + ingress_rules = ["tcp-80-tcp","tcp-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(s) in, allow everthing out" From 3073e99b529594dae9cb5e25df2ee758b8969288 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 21:10:31 +0100 Subject: [PATCH 11/89] fixed module sg ingress_rules array with correct https vars --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index cad2d347f4..85ebc1eb21 100644 --- a/main.tf +++ b/main.tf @@ -36,7 +36,7 @@ module "blog_sg" { vpc_id = data.aws_vpc.default.id - ingress_rules = ["tcp-80-tcp","tcp-443-tcp"] + ingress_rules = ["http-80-tcp","https-443-tcp"] ingress_cidr_blocks = ["0.0.0.0/0"] egress_rules = ["all-all"] From b1cccb98170a03083373f16b9666f5d5767d2b01 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 22:14:25 +0100 Subject: [PATCH 12/89] scale 0 --- main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/main.tf b/main.tf index 85ebc1eb21..409b1adfa5 100644 --- a/main.tf +++ b/main.tf @@ -1,4 +1,5 @@ data "aws_ami" "app_ami" { + count = 0 most_recent = true filter { From ce1d2ebc3cd1f9e652200e24385ab9e2dae6cc16 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 22:16:05 +0100 Subject: [PATCH 13/89] scale 0 --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 409b1adfa5..c0535b4622 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,4 @@ data "aws_ami" "app_ami" { - count = 0 most_recent = true filter { @@ -20,6 +19,7 @@ data "aws_vpc" "default"{ } resource "aws_instance" "blog" { + count = 0 ami = data.aws_ami.app_ami.id instance_type = var.instance_type From 14e18bc55b2214963f3b2940e5293de55eaa3fb9 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 22:17:59 +0100 Subject: [PATCH 14/89] scale 0 --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index c0535b4622..dbe181be62 100644 --- a/main.tf +++ b/main.tf @@ -19,7 +19,7 @@ data "aws_vpc" "default"{ } resource "aws_instance" "blog" { - count = 0 + count = 0 ami = data.aws_ami.app_ami.id instance_type = var.instance_type From 5fff736f54ba8e79642d7c8ca83fa9ad32c3535a Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sun, 6 Jul 2025 22:26:32 +0100 Subject: [PATCH 15/89] scale removed --- main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/main.tf b/main.tf index dbe181be62..85ebc1eb21 100644 --- a/main.tf +++ b/main.tf @@ -19,7 +19,6 @@ data "aws_vpc" "default"{ } resource "aws_instance" "blog" { - count = 0 ami = data.aws_ami.app_ami.id instance_type = var.instance_type From 07ad6669dbe2b756acf2afc4c93eefa26688302b Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 08:22:14 +0100 Subject: [PATCH 16/89] create new dev vpc --- main.tf | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 85ebc1eb21..855c3f29d4 100644 --- a/main.tf +++ b/main.tf @@ -18,12 +18,29 @@ data "aws_vpc" "default"{ default = true } +module "blog_vpc" { + source = "terraform-aws-modules/vpc/aws" + + name = "dev" + cidr = "10.0.0.0/16" + + #azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"] + public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] + + tags = { + Terraform = "true" + Environment = "dev" + } +} + resource "aws_instance" "blog" { ami = data.aws_ami.app_ami.id instance_type = var.instance_type vpc_security_group_ids = [module.blog_sg.security_group_id] + subnet_id = module.blog_vpc.default.id + tags = { Name = "Learning Terraform" } @@ -34,7 +51,7 @@ module "blog_sg" { version = "5.3.0" 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 aca2f4be9bb257c860d1fa4d2bd9d1dde89a23f2 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 08:27:00 +0100 Subject: [PATCH 17/89] fix instance subnet_id = module.blog_vpc.public_subnets[0] --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 855c3f29d4..a2405da4bb 100644 --- a/main.tf +++ b/main.tf @@ -39,7 +39,7 @@ resource "aws_instance" "blog" { vpc_security_group_ids = [module.blog_sg.security_group_id] - subnet_id = module.blog_vpc.default.id + subnet_id = module.blog_vpc.public_subnets[0] tags = { Name = "Learning Terraform" From a8a2ce9600d9a4ce2f42b3dc9bd16de9466c1b42 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 08:29:23 +0100 Subject: [PATCH 18/89] fix azs --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index a2405da4bb..8c91171882 100644 --- a/main.tf +++ b/main.tf @@ -24,7 +24,7 @@ module "blog_vpc" { name = "dev" cidr = "10.0.0.0/16" - #azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"] + azs = [] public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] tags = { From 5cd5c9c61c75fb43af36bb557b98ef6d0fb0525b Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 08:30:43 +0100 Subject: [PATCH 19/89] 2nd fix azs --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 8c91171882..fe3d84d459 100644 --- a/main.tf +++ b/main.tf @@ -24,7 +24,7 @@ module "blog_vpc" { name = "dev" cidr = "10.0.0.0/16" - azs = [] + azs = ["eu-north-1"] public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] tags = { From c8eea47c3a957fb7d51298b6257480b87b029f5b Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 10:05:59 +0100 Subject: [PATCH 20/89] fix provider region eu-north-1 --- providers.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers.tf b/providers.tf index c41e3650b5..085443e4bd 100644 --- a/providers.tf +++ b/providers.tf @@ -7,5 +7,5 @@ terraform { } provider "aws" { - region = "us-west-2" + region = "eu-north-1" } From 36977a9b8cd507fa301c96ef6e7ea4652f63ed2a Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 10:08:26 +0100 Subject: [PATCH 21/89] fix azs azs = ["eu-north-1a", "eu-north-1b", "eu-north-1c"] --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index fe3d84d459..cd0835887f 100644 --- a/main.tf +++ b/main.tf @@ -24,7 +24,7 @@ module "blog_vpc" { name = "dev" cidr = "10.0.0.0/16" - azs = ["eu-north-1"] + azs = ["eu-north-1a", "eu-north-1b", "eu-north-1c"] public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] tags = { From a1b6b07631a1bfbdd713575af559585998e1beda Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 10:16:54 +0100 Subject: [PATCH 22/89] removed aws_security_group.blog as its not needed due to module "blog_sg" --- main.tf | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/main.tf b/main.tf index cd0835887f..6e978c22fb 100644 --- a/main.tf +++ b/main.tf @@ -58,31 +58,4 @@ module "blog_sg" { egress_rules = ["all-all"] egress_cidr_blocks = ["0.0.0.0/0"] -} - -resource "aws_security_group" "blog" { - name = "blog" - description = "Allow http(s) in, allow everthing out" - - 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_all_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 6e683f1757c0ff763c90c7e91a6340e988965387 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 21:46:40 +0100 Subject: [PATCH 23/89] loadbalancer --- main.tf | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/main.tf b/main.tf index 6e978c22fb..398d69a3df 100644 --- a/main.tf +++ b/main.tf @@ -46,6 +46,36 @@ resource "aws_instance" "blog" { } } +module "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] + + http_tcp_listeners = { + { + port = 80 + protocol = "http" + targer_group_index = 0 + } + } + target_groups = { + ex-instance = { + name_prefix = "blog-" + protocol = "HTTP" + port = 80 + target_type = "instance" + target_id = aws_instance.blog.id + } + } + + tags = { + Environment = "Dev" + } +} + module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.0" From f21b9f3c48167571761b9b44aeb5dd7a9cc2e06b Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 21:48:17 +0100 Subject: [PATCH 24/89] fix http_tcp_listeners = { { port = 80 protocol = "http" target_group_index = 0 } } --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 398d69a3df..48511393bb 100644 --- a/main.tf +++ b/main.tf @@ -58,7 +58,7 @@ module "alb" { { port = 80 protocol = "http" - targer_group_index = 0 + target_group_index = 0 } } target_groups = { From 00ae9d883128e9185b3927cf3eacc2003f052471 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 21:50:24 +0100 Subject: [PATCH 25/89] fix protocol = "HTTP" --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 48511393bb..503e8baa0f 100644 --- a/main.tf +++ b/main.tf @@ -57,7 +57,7 @@ module "alb" { http_tcp_listeners = { { port = 80 - protocol = "http" + protocol = "HTTP" target_group_index = 0 } } From 32ad6e539fb2f625d3cefbcfc91f9a72e9baee65 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 21:53:42 +0100 Subject: [PATCH 26/89] changed http_tcp_listeners to array --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 503e8baa0f..55eece9a92 100644 --- a/main.tf +++ b/main.tf @@ -54,13 +54,13 @@ module "alb" { subnets = module.blog_vpc.public_subnets security_groups = [module.blog_sg.security_group_id] - http_tcp_listeners = { + http_tcp_listeners = [ { port = 80 protocol = "HTTP" target_group_index = 0 } - } + ] target_groups = { ex-instance = { name_prefix = "blog-" From 3317ea25758d41bffc35e931c56b1c9021c42814 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 21:56:03 +0100 Subject: [PATCH 27/89] fix module "alb" --- main.tf | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/main.tf b/main.tf index 55eece9a92..ab40bcbdd9 100644 --- a/main.tf +++ b/main.tf @@ -47,29 +47,36 @@ resource "aws_instance" "blog" { } module "alb" { - source = "terraform-aws-modules/alb/aws" + source = "terraform-aws-modules/alb/aws" + version = "9.7.0" # or latest - name = "blog-alb" - vpc_id = module.blog_vpc.vpc_id - subnets = module.blog_vpc.public_subnets - security_groups = [module.blog_sg.security_group_id] + name = "blog-alb" + vpc_id = module.blog_vpc.vpc_id + subnets = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] + load_balancer_type = "application" - http_tcp_listeners = [ + target_groups = [ { - port = 80 - protocol = "HTTP" - target_group_index = 0 + name_prefix = "blog-" + backend_protocol = "HTTP" + backend_port = 80 + target_type = "instance" + targets = [ + { + target_id = aws_instance.blog.id + } + ] } ] - target_groups = { - ex-instance = { - name_prefix = "blog-" - protocol = "HTTP" - port = 80 - target_type = "instance" - target_id = aws_instance.blog.id + + listeners = [ + { + port = 80 + protocol = "HTTP" + target_group_index = 0 } - } + ] tags = { Environment = "Dev" From a186fa40c9c639224ef8ea479b9d5fed8388c027 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:02:02 +0100 Subject: [PATCH 28/89] fix target_id = aws_instance.blog.id --- main.tf | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/main.tf b/main.tf index ab40bcbdd9..92104add21 100644 --- a/main.tf +++ b/main.tf @@ -62,11 +62,7 @@ module "alb" { backend_protocol = "HTTP" backend_port = 80 target_type = "instance" - targets = [ - { - target_id = aws_instance.blog.id - } - ] + target_id = aws_instance.blog.id } ] From c875359990699c2755f6a50722f1c1000353267c Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:16:43 +0100 Subject: [PATCH 29/89] test lb --- main.tf | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/main.tf b/main.tf index 92104add21..3f70612a65 100644 --- a/main.tf +++ b/main.tf @@ -47,35 +47,34 @@ resource "aws_instance" "blog" { } module "alb" { - source = "terraform-aws-modules/alb/aws" - version = "9.7.0" # or latest + 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] - load_balancer_type = "application" + name = "blog-" + vpc_id = module.blog_vpc.vpc_id + subnets = module.blog_vpc.subnets + security_groups = [module.blog_vpc.security_group_id] - target_groups = [ + listeners = { { - name_prefix = "blog-" - backend_protocol = "HTTP" - backend_port = 80 - target_type = "instance" - target_id = aws_instance.blog.id + port = 80 + protocol = "HTTP" } - ] - listeners = [ - { - port = 80 - protocol = "HTTP" - target_group_index = 0 + } + + target_groups = { + ex-instance = { + name_prefix = "blog-" + protocol = "HTTP" + port = 80 + target_type = "instance" + target_id = aws_instance.blog.id } - ] + } tags = { - Environment = "Dev" + Environment = "Development" + Project = "Example" } } From 36dafc34665208575876137ea5ca27b814576309 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:20:58 +0100 Subject: [PATCH 30/89] test lb --- main.tf | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 3f70612a65..222ebe5cd1 100644 --- a/main.tf +++ b/main.tf @@ -72,9 +72,18 @@ module "alb" { } } +<<<<<<< HEAD + listeners = { + port = 80 + protocol = "HTTP" + target_group_index = 0 + } + + +======= +>>>>>>> c875359990699c2755f6a50722f1c1000353267c tags = { - Environment = "Development" - Project = "Example" + Environment = "Dev" } } From 2c8aee4cf26ead1a05315327933347bc42e9a1e9 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:22:41 +0100 Subject: [PATCH 31/89] test lb --- main.tf | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/main.tf b/main.tf index 222ebe5cd1..3efacd9124 100644 --- a/main.tf +++ b/main.tf @@ -72,16 +72,14 @@ module "alb" { } } -<<<<<<< HEAD - listeners = { + listeners = [ + { port = 80 protocol = "HTTP" target_group_index = 0 - } - + } + ] -======= ->>>>>>> c875359990699c2755f6a50722f1c1000353267c tags = { Environment = "Dev" } From 7e8a05eae4de121fa8c2cc0f2ae9cba88f4f1bdd Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:23:34 +0100 Subject: [PATCH 32/89] tes lb --- main.tf | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/main.tf b/main.tf index 3efacd9124..f165429b16 100644 --- a/main.tf +++ b/main.tf @@ -54,13 +54,13 @@ module "alb" { subnets = module.blog_vpc.subnets security_groups = [module.blog_vpc.security_group_id] - listeners = { + listeners = [ { - port = 80 - protocol = "HTTP" + port = 80 + protocol = "HTTP" + target_group_index = 0 } - - } + ] target_groups = { ex-instance = { @@ -72,14 +72,6 @@ module "alb" { } } - listeners = [ - { - port = 80 - protocol = "HTTP" - target_group_index = 0 - } - ] - tags = { Environment = "Dev" } From 90c453de7c8b45e902271bcb13b430c24c16949c Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:26:48 +0100 Subject: [PATCH 33/89] test lb --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index f165429b16..f760dd8141 100644 --- a/main.tf +++ b/main.tf @@ -51,8 +51,8 @@ module "alb" { name = "blog-" vpc_id = module.blog_vpc.vpc_id - subnets = module.blog_vpc.subnets - security_groups = [module.blog_vpc.security_group_id] + subnets = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] listeners = [ { From 8e6e552597ceba0d01e179420853052f73ccf91d Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:29:02 +0100 Subject: [PATCH 34/89] test lb --- main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/main.tf b/main.tf index f760dd8141..9b99ba80c3 100644 --- a/main.tf +++ b/main.tf @@ -64,7 +64,6 @@ module "alb" { target_groups = { ex-instance = { - name_prefix = "blog-" protocol = "HTTP" port = 80 target_type = "instance" From cdc90ce357944600b64c57f934ecfe3aba3315f3 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:30:36 +0100 Subject: [PATCH 35/89] test lb --- main.tf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 9b99ba80c3..ebef45ae72 100644 --- a/main.tf +++ b/main.tf @@ -49,7 +49,7 @@ resource "aws_instance" "blog" { module "alb" { source = "terraform-aws-modules/alb/aws" - name = "blog-" + name = "blog_alb" vpc_id = module.blog_vpc.vpc_id subnets = module.blog_vpc.public_subnets security_groups = [module.blog_sg.security_group_id] @@ -64,6 +64,7 @@ module "alb" { target_groups = { ex-instance = { + name_prefix = "blog-" protocol = "HTTP" port = 80 target_type = "instance" From 5b4401a45ed744429ad5000a2226f0031698cbaf Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:32:52 +0100 Subject: [PATCH 36/89] tes lb --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index ebef45ae72..28951f592f 100644 --- a/main.tf +++ b/main.tf @@ -49,7 +49,7 @@ resource "aws_instance" "blog" { module "alb" { source = "terraform-aws-modules/alb/aws" - name = "blog_alb" + name = "blog-alb" vpc_id = module.blog_vpc.vpc_id subnets = module.blog_vpc.public_subnets security_groups = [module.blog_sg.security_group_id] From c3fe5f9bea07c7fb6cd819d10855e2706dbd6d48 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:37:26 +0100 Subject: [PATCH 37/89] test lb --- main.tf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 28951f592f..c351ab661a 100644 --- a/main.tf +++ b/main.tf @@ -68,7 +68,11 @@ module "alb" { protocol = "HTTP" port = 80 target_type = "instance" - target_id = aws_instance.blog.id + target_id = [ + { + target_id = aws_instance.blog.id + } + ] } } From ed48d406e8d1dadac22b6bbfce97563c7afedfe2 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:40:44 +0100 Subject: [PATCH 38/89] test lb --- main.tf | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/main.tf b/main.tf index c351ab661a..5f53291e3d 100644 --- a/main.tf +++ b/main.tf @@ -62,23 +62,20 @@ module "alb" { } ] - target_groups = { - ex-instance = { + target_groups = [ + { name_prefix = "blog-" - protocol = "HTTP" - port = 80 + backend_protocol = "HTTP" + backend_port = 80 target_type = "instance" - target_id = [ + + targets = [ { target_id = aws_instance.blog.id - } + } ] } - } - - tags = { - Environment = "Dev" - } + ] } module "blog_sg" { From c72ecc1febee018368c2a201cba3bbd1f00532e0 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:43:29 +0100 Subject: [PATCH 39/89] test lb --- main.tf | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/main.tf b/main.tf index 5f53291e3d..3ed553a1fc 100644 --- a/main.tf +++ b/main.tf @@ -47,12 +47,14 @@ resource "aws_instance" "blog" { } module "alb" { - source = "terraform-aws-modules/alb/aws" + source = "terraform-aws-modules/alb/aws" + version = "9.17.0" - name = "blog-alb" - vpc_id = module.blog_vpc.vpc_id - subnets = module.blog_vpc.public_subnets - security_groups = [module.blog_sg.security_group_id] + name = "blog-alb" + vpc_id = module.blog_vpc.vpc_id + subnets = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] + load_balancer_type = "application" listeners = [ { @@ -60,7 +62,7 @@ module "alb" { protocol = "HTTP" target_group_index = 0 } - ] + ] target_groups = [ { @@ -68,7 +70,6 @@ module "alb" { backend_protocol = "HTTP" backend_port = 80 target_type = "instance" - targets = [ { target_id = aws_instance.blog.id @@ -76,8 +77,12 @@ module "alb" { ] } ] -} + tags = { + Environment = "Development" + Project = "Example" + } +} module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.0" From 612d62c112bd56009098246a55e4cad35e95e964 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 22:51:00 +0100 Subject: [PATCH 40/89] test --- main.tf | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/main.tf b/main.tf index 3ed553a1fc..1b629d8f87 100644 --- a/main.tf +++ b/main.tf @@ -46,43 +46,7 @@ resource "aws_instance" "blog" { } } -module "alb" { - source = "terraform-aws-modules/alb/aws" - version = "9.17.0" - - name = "blog-alb" - vpc_id = module.blog_vpc.vpc_id - subnets = module.blog_vpc.public_subnets - security_groups = [module.blog_sg.security_group_id] - load_balancer_type = "application" - - listeners = [ - { - port = 80 - protocol = "HTTP" - target_group_index = 0 - } - ] - - target_groups = [ - { - name_prefix = "blog-" - backend_protocol = "HTTP" - backend_port = 80 - target_type = "instance" - targets = [ - { - target_id = aws_instance.blog.id - } - ] - } - ] - tags = { - Environment = "Development" - Project = "Example" - } -} module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.0" From 1196bf09c9d2b5d37bb5ac45f0599801b43dfca7 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 23:15:35 +0100 Subject: [PATCH 41/89] test lb --- main.tf | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/main.tf b/main.tf index 1b629d8f87..3ed553a1fc 100644 --- a/main.tf +++ b/main.tf @@ -46,7 +46,43 @@ resource "aws_instance" "blog" { } } +module "alb" { + source = "terraform-aws-modules/alb/aws" + version = "9.17.0" + + name = "blog-alb" + vpc_id = module.blog_vpc.vpc_id + subnets = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] + load_balancer_type = "application" + + listeners = [ + { + port = 80 + protocol = "HTTP" + target_group_index = 0 + } + ] + + target_groups = [ + { + name_prefix = "blog-" + backend_protocol = "HTTP" + backend_port = 80 + target_type = "instance" + targets = [ + { + target_id = aws_instance.blog.id + } + ] + } + ] + tags = { + Environment = "Development" + Project = "Example" + } +} module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.0" From 9307b5ce21c2618d6ab50f45f29cf9bd832df8fb Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 23:27:15 +0100 Subject: [PATCH 42/89] test lb --- main.tf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 3ed553a1fc..e6bf7b9da8 100644 --- a/main.tf +++ b/main.tf @@ -79,8 +79,7 @@ module "alb" { ] tags = { - Environment = "Development" - Project = "Example" + Environment = "Dev" } } module "blog_sg" { From ecd86d2f6361fb6716fca711b7f4a9348d5ee192 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 23:33:47 +0100 Subject: [PATCH 43/89] test lb --- main.tf | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/main.tf b/main.tf index e6bf7b9da8..6cc5c40bd9 100644 --- a/main.tf +++ b/main.tf @@ -48,21 +48,13 @@ resource "aws_instance" "blog" { module "alb" { source = "terraform-aws-modules/alb/aws" - version = "9.17.0" + version = "4.0.0" # Last known version compatible with Terraform v0.12-v1.2 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] - load_balancer_type = "application" - - listeners = [ - { - port = 80 - protocol = "HTTP" - target_group_index = 0 - } - ] target_groups = [ { @@ -70,18 +62,19 @@ module "alb" { backend_protocol = "HTTP" backend_port = 80 target_type = "instance" - targets = [ - { - target_id = aws_instance.blog.id - } - ] + target_id = aws_instance.blog.id } ] - tags = { - Environment = "Dev" - } + listeners = [ + { + port = 80 + protocol = "HTTP" + target_group_index = 0 + } + ] } + module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.0" From 5f5d2fc365c279f82e1deeeda0c83c3cade1e9f0 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 23:35:15 +0100 Subject: [PATCH 44/89] test lb --- main.tf | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/main.tf b/main.tf index 6cc5c40bd9..ca63a271c7 100644 --- a/main.tf +++ b/main.tf @@ -48,31 +48,43 @@ resource "aws_instance" "blog" { module "alb" { source = "terraform-aws-modules/alb/aws" - version = "4.0.0" # Last known version compatible with Terraform v0.12-v1.2 + version = "4.0.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] + load_balancer_name = "blog-alb" + + vpc_id = module.blog_vpc.vpc_id + subnets = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] + + internal = false + idle_timeout = 60 + enable_deletion_protection = false target_groups = [ { - name_prefix = "blog-" + name_prefix = "blog" backend_protocol = "HTTP" backend_port = 80 target_type = "instance" - target_id = aws_instance.blog.id + targets = [ + { + target_id = aws_instance.blog.id + } + ] } ] - listeners = [ + http_tcp_listeners = [ { port = 80 protocol = "HTTP" target_group_index = 0 } ] + + tags = { + Environment = "Dev" + } } module "blog_sg" { From 17b0cbc01baa093e234c5d19c39deb87f2139344 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 23:36:08 +0100 Subject: [PATCH 45/89] test lb --- main.tf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main.tf b/main.tf index ca63a271c7..575b871a41 100644 --- a/main.tf +++ b/main.tf @@ -56,10 +56,6 @@ module "alb" { subnets = module.blog_vpc.public_subnets security_groups = [module.blog_sg.security_group_id] - internal = false - idle_timeout = 60 - enable_deletion_protection = false - target_groups = [ { name_prefix = "blog" From 469489a13ab9b3add7d5cb5ae72af71f99101390 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 23:37:25 +0100 Subject: [PATCH 46/89] tes lb --- main.tf | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/main.tf b/main.tf index 575b871a41..23b3faa76f 100644 --- a/main.tf +++ b/main.tf @@ -62,11 +62,7 @@ module "alb" { backend_protocol = "HTTP" backend_port = 80 target_type = "instance" - targets = [ - { - target_id = aws_instance.blog.id - } - ] + targets = target_id = aws_instance.blog.id } ] From b286a23cca193f2fd68d642493302e2d5dd06bb9 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 23:39:03 +0100 Subject: [PATCH 47/89] test lb --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 23b3faa76f..c7f4142089 100644 --- a/main.tf +++ b/main.tf @@ -58,11 +58,11 @@ module "alb" { target_groups = [ { - name_prefix = "blog" + name_prefix = "blog-" backend_protocol = "HTTP" backend_port = 80 target_type = "instance" - targets = target_id = aws_instance.blog.id + target_id = aws_instance.blog.id } ] From bd29caea7d346ca73273a7cc01b47b60f8b8ff72 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 23:56:45 +0100 Subject: [PATCH 48/89] scalling --- main.tf | 21 ++++++++++++++++++--- outputs.tf | 6 ------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/main.tf b/main.tf index c7f4142089..0270fa14ab 100644 --- a/main.tf +++ b/main.tf @@ -46,7 +46,23 @@ resource "aws_instance" "blog" { } } -module "alb" { +module "autoscaling" { + source = "terraform-aws-modules/autoscaling/aws" + version = "9.0.1" + + 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] + + image_id = data.aws_ami.app_ami.id + instance = var.instance_type +} + +module "blog_alb" { source = "terraform-aws-modules/alb/aws" version = "4.0.0" @@ -61,8 +77,7 @@ module "alb" { name_prefix = "blog-" backend_protocol = "HTTP" backend_port = 80 - target_type = "instance" - target_id = aws_instance.blog.id + target_type = "instance" } ] diff --git a/outputs.tf b/outputs.tf index 7e9410b55c..8b13789179 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,7 +1 @@ -output "instance_ami" { - value = aws_instance.blog.ami -} -output "instance_arn" { - value = aws_instance.blog.arn -} From eff84779106459b410d1e55adbb889e25c17f90c Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Mon, 7 Jul 2025 23:59:06 +0100 Subject: [PATCH 49/89] test scalling --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 0270fa14ab..660ade03d9 100644 --- a/main.tf +++ b/main.tf @@ -77,7 +77,7 @@ module "blog_alb" { name_prefix = "blog-" backend_protocol = "HTTP" backend_port = 80 - target_type = "instance" + target_type = "instance" } ] From ad273caa762b668f96e9a2cdf270871ec600d793 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:03:05 +0100 Subject: [PATCH 50/89] test scalling --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 660ade03d9..1522428c54 100644 --- a/main.tf +++ b/main.tf @@ -55,11 +55,11 @@ module "autoscaling" { max_size = 2 vpc_zone_identifier = module.blog_vpc.public_subnets - target_group_arns = module.blog_alb.target_group_arns + autoscaling_group_target_group_arns = module.blog_alb.target_group_arns security_groups = [module.blog_sg.security_group_id] image_id = data.aws_ami.app_ami.id - instance = var.instance_type + instance_type = var.instance_type } module "blog_alb" { From d66b9dd7d7d2360c7c3ad8457d60775740f5580d Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:04:04 +0100 Subject: [PATCH 51/89] test scalling --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 1522428c54..5b828b1227 100644 --- a/main.tf +++ b/main.tf @@ -55,7 +55,7 @@ module "autoscaling" { max_size = 2 vpc_zone_identifier = module.blog_vpc.public_subnets - autoscaling_group_target_group_arns = module.blog_alb.target_group_arns + target_group_arns = module.blog_alb.target_group_arns security_groups = [module.blog_sg.security_group_id] image_id = data.aws_ami.app_ami.id From 28b105f9757ec0e6758e1a9a230855411ac0c6f5 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:06:38 +0100 Subject: [PATCH 52/89] test autoscalling --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 5b828b1227..1522428c54 100644 --- a/main.tf +++ b/main.tf @@ -55,7 +55,7 @@ module "autoscaling" { max_size = 2 vpc_zone_identifier = module.blog_vpc.public_subnets - target_group_arns = module.blog_alb.target_group_arns + autoscaling_group_target_group_arns = module.blog_alb.target_group_arns security_groups = [module.blog_sg.security_group_id] image_id = data.aws_ami.app_ami.id From dfbf4fd8e3e152c2ac3c65e009bb7e26df16284b Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:07:46 +0100 Subject: [PATCH 53/89] test scalling --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 1522428c54..62e31edfd3 100644 --- a/main.tf +++ b/main.tf @@ -48,14 +48,14 @@ resource "aws_instance" "blog" { module "autoscaling" { source = "terraform-aws-modules/autoscaling/aws" - version = "9.0.1" + version = "6.5.2" name ="blog" min_size = 1 max_size = 2 vpc_zone_identifier = module.blog_vpc.public_subnets - autoscaling_group_target_group_arns = module.blog_alb.target_group_arns + target_group_arns = module.blog_alb.target_group_arns security_groups = [module.blog_sg.security_group_id] image_id = data.aws_ami.app_ami.id From ffb6572b4f6c23b793f2234bf388562399870be2 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:09:11 +0100 Subject: [PATCH 54/89] test scalling --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 62e31edfd3..1522428c54 100644 --- a/main.tf +++ b/main.tf @@ -48,14 +48,14 @@ resource "aws_instance" "blog" { module "autoscaling" { source = "terraform-aws-modules/autoscaling/aws" - version = "6.5.2" + version = "9.0.1" 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 + autoscaling_group_target_group_arns = module.blog_alb.target_group_arns security_groups = [module.blog_sg.security_group_id] image_id = data.aws_ami.app_ami.id From 1daeeff7b43689e531a0fad820247f3bf2232ed7 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:10:52 +0100 Subject: [PATCH 55/89] test scalling --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 1522428c54..5b828b1227 100644 --- a/main.tf +++ b/main.tf @@ -55,7 +55,7 @@ module "autoscaling" { max_size = 2 vpc_zone_identifier = module.blog_vpc.public_subnets - autoscaling_group_target_group_arns = module.blog_alb.target_group_arns + target_group_arns = module.blog_alb.target_group_arns security_groups = [module.blog_sg.security_group_id] image_id = data.aws_ami.app_ami.id From a7ba20609ead69e4ffdb36ac14ab147b507f463a Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:16:41 +0100 Subject: [PATCH 56/89] test scalling --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 5b828b1227..74b918b39d 100644 --- a/main.tf +++ b/main.tf @@ -64,7 +64,7 @@ module "autoscaling" { module "blog_alb" { source = "terraform-aws-modules/alb/aws" - version = "4.0.0" + version = "9.17.0" load_balancer_name = "blog-alb" From fdd11f90b40719ec54844ee0c7efc1f063f9027c Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:18:22 +0100 Subject: [PATCH 57/89] test scalling --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 74b918b39d..d8621fc0aa 100644 --- a/main.tf +++ b/main.tf @@ -55,7 +55,7 @@ module "autoscaling" { max_size = 2 vpc_zone_identifier = module.blog_vpc.public_subnets - target_group_arns = module.blog_alb.target_group_arns + target_group_arns_attach = module.blog_alb.target_group_arns security_groups = [module.blog_sg.security_group_id] image_id = data.aws_ami.app_ami.id From 01c6e5efd7319de4ff873dbf0d72718a53bccddc Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:21:05 +0100 Subject: [PATCH 58/89] test scalling --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index d8621fc0aa..ef7b771697 100644 --- a/main.tf +++ b/main.tf @@ -55,7 +55,7 @@ module "autoscaling" { max_size = 2 vpc_zone_identifier = module.blog_vpc.public_subnets - target_group_arns_attach = module.blog_alb.target_group_arns + autoscaling_group_target_group_arns = module.blog_alb.target_group_arns security_groups = [module.blog_sg.security_group_id] image_id = data.aws_ami.app_ami.id From 2b931766738b7118d0e519bcaceeb282e86df8f6 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:25:52 +0100 Subject: [PATCH 59/89] test scalling --- main.tf | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index ef7b771697..05ddd991f9 100644 --- a/main.tf +++ b/main.tf @@ -55,7 +55,12 @@ module "autoscaling" { max_size = 2 vpc_zone_identifier = module.blog_vpc.public_subnets - autoscaling_group_target_group_arns = module.blog_alb.target_group_arns + traffic_source_attachments = { + alb = { + traffic_source_arn = element(module.blog_alb.target_group_arns, 0) + type = "elbv2" + } + } security_groups = [module.blog_sg.security_group_id] image_id = data.aws_ami.app_ami.id From b7b13b30a6b23aedb47c63fac1cad6b5d3a0e626 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:28:10 +0100 Subject: [PATCH 60/89] fix lb for autoscalling --- main.tf | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/main.tf b/main.tf index 05ddd991f9..12507a6907 100644 --- a/main.tf +++ b/main.tf @@ -71,28 +71,36 @@ module "blog_alb" { source = "terraform-aws-modules/alb/aws" version = "9.17.0" - load_balancer_name = "blog-alb" - - vpc_id = module.blog_vpc.vpc_id - subnets = module.blog_vpc.public_subnets - security_groups = [module.blog_sg.security_group_id] + load_balancers = { + blog = { + name = "blog-alb" + internal = false + load_balancer_type = "application" + subnets = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] + } + } - target_groups = [ - { - name_prefix = "blog-" - backend_protocol = "HTTP" - backend_port = 80 - target_type = "instance" + target_groups = { + blog = { + name_prefix = "blog-" + protocol = "HTTP" + port = 80 + target_type = "instance" } - ] + } - http_tcp_listeners = [ - { - port = 80 - protocol = "HTTP" - target_group_index = 0 + listeners = { + http = { + port = 80 + protocol = "HTTP" + forward = { + target_group_key = "blog" + } } - ] + } + + vpc_id = module.blog_vpc.vpc_id tags = { Environment = "Dev" From 40a072e3dc8adf84f0f6d32db88a7684f05672e9 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:31:20 +0100 Subject: [PATCH 61/89] tes new lb --- main.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.tf b/main.tf index 12507a6907..3d82e51708 100644 --- a/main.tf +++ b/main.tf @@ -71,6 +71,8 @@ module "blog_alb" { source = "terraform-aws-modules/alb/aws" version = "9.17.0" + vpc_id = module.blog_vpc.vpc_id + load_balancers = { blog = { name = "blog-alb" @@ -83,10 +85,10 @@ module "blog_alb" { target_groups = { blog = { - name_prefix = "blog-" - protocol = "HTTP" - port = 80 - target_type = "instance" + name_prefix = "blog-" + protocol = "HTTP" + port = 80 + target_type = "instance" } } @@ -100,8 +102,6 @@ module "blog_alb" { } } - vpc_id = module.blog_vpc.vpc_id - tags = { Environment = "Dev" } From c9327f0c43ed0efa663c1b5ac357c828e08020c4 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:34:19 +0100 Subject: [PATCH 62/89] test lb with scalling --- main.tf | 143 +++++++++++++++++++++++++++----------------------------- 1 file changed, 70 insertions(+), 73 deletions(-) diff --git a/main.tf b/main.tf index 3d82e51708..4ae35454dd 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,18 @@ +terraform { + required_version = "= 1.12.2" + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.0" + } + } +} + +provider "aws" { + region = "eu-north-1" +} + data "aws_ami" "app_ami" { most_recent = true @@ -14,109 +29,91 @@ data "aws_ami" "app_ami" { owners = ["979382823631"] # Bitnami } -data "aws_vpc" "default"{ - default = true -} - module "blog_vpc" { - source = "terraform-aws-modules/vpc/aws" + source = "terraform-aws-modules/vpc/aws" + version = "2.77.0" name = "dev" cidr = "10.0.0.0/16" - azs = ["eu-north-1a", "eu-north-1b", "eu-north-1c"] - public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] + azs = ["eu-north-1a", "eu-north-1b", "eu-north-1c"] + public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] + + enable_dns_hostnames = true tags = { - Terraform = "true" + Terraform = "true" Environment = "dev" } } -resource "aws_instance" "blog" { - ami = data.aws_ami.app_ami.id - instance_type = var.instance_type - - vpc_security_group_ids = [module.blog_sg.security_group_id] - - subnet_id = module.blog_vpc.public_subnets[0] - - tags = { - Name = "Learning Terraform" - } -} +module "blog_sg" { + source = "terraform-aws-modules/security-group/aws" + version = "3.17.0" -module "autoscaling" { - source = "terraform-aws-modules/autoscaling/aws" - version = "9.0.1" - - name ="blog" - min_size = 1 - max_size = 2 + name = "blog-sg" + vpc_id = module.blog_vpc.vpc_id - vpc_zone_identifier = module.blog_vpc.public_subnets - traffic_source_attachments = { - alb = { - traffic_source_arn = element(module.blog_alb.target_group_arns, 0) - type = "elbv2" - } - } - security_groups = [module.blog_sg.security_group_id] + ingress_rules = ["http-80-tcp", "https-443-tcp"] + ingress_cidr_blocks = ["0.0.0.0/0"] - image_id = data.aws_ami.app_ami.id - instance_type = var.instance_type + egress_rules = ["all-all"] + egress_cidr_blocks = ["0.0.0.0/0"] } module "blog_alb" { source = "terraform-aws-modules/alb/aws" - version = "9.17.0" + version = "5.12.0" - vpc_id = module.blog_vpc.vpc_id + name = "blog-alb" + load_balancer_type = "application" - load_balancers = { - blog = { - name = "blog-alb" - internal = false - load_balancer_type = "application" - subnets = module.blog_vpc.public_subnets - security_groups = [module.blog_sg.security_group_id] - } - } + subnets = module.blog_vpc.public_subnets + vpc_id = module.blog_vpc.vpc_id + security_groups = [module.blog_sg.security_group_id] - target_groups = { - blog = { - name_prefix = "blog-" - protocol = "HTTP" - port = 80 - target_type = "instance" + target_groups = [ + { + name_prefix = "blog-" + backend_protocol = "HTTP" + backend_port = 80 + target_type = "instance" } - } + ] - listeners = { - http = { - port = 80 - protocol = "HTTP" - forward = { - target_group_key = "blog" - } + http_tcp_listeners = [ + { + port = 80 + protocol = "HTTP" + target_group_index = 0 } - } + ] tags = { Environment = "Dev" } } -module "blog_sg" { - source = "terraform-aws-modules/security-group/aws" - version = "5.3.0" - name = "blog_new" +module "autoscaling" { + source = "terraform-aws-modules/autoscaling/aws" + version = "4.1.0" - vpc_id = module.blog_vpc.vpc_id + name = "blog-asg" + min_size = 1 + max_size = 2 + desired_capacity = 1 + vpc_zone_identifier = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] - ingress_rules = ["http-80-tcp","https-443-tcp"] - ingress_cidr_blocks = ["0.0.0.0/0"] + launch_template = { + name_prefix = "blog-launch" + image_id = data.aws_ami.app_ami.id + instance_type = "t3.micro" + } - egress_rules = ["all-all"] - egress_cidr_blocks = ["0.0.0.0/0"] -} \ No newline at end of file + target_group_arns = module.blog_alb.target_group_arns +} + +output "alb_dns_name" { + value = module.blog_alb.dns_name +} From de2bacd864e88eebefa26bafb1c8b046a6804f42 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:35:38 +0100 Subject: [PATCH 63/89] test lb with scalling --- main.tf | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/main.tf b/main.tf index 4ae35454dd..c5342ca51f 100644 --- a/main.tf +++ b/main.tf @@ -1,18 +1,3 @@ -terraform { - required_version = "= 1.12.2" - - required_providers { - aws = { - source = "hashicorp/aws" - version = "~> 3.0" - } - } -} - -provider "aws" { - region = "eu-north-1" -} - data "aws_ami" "app_ami" { most_recent = true From b82bbd2a4112d720226ed88ba09ac023b445169c Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:44:34 +0100 Subject: [PATCH 64/89] test lb scalling --- main.tf | 128 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 55 deletions(-) diff --git a/main.tf b/main.tf index c5342ca51f..3d82e51708 100644 --- a/main.tf +++ b/main.tf @@ -14,91 +14,109 @@ data "aws_ami" "app_ami" { owners = ["979382823631"] # Bitnami } +data "aws_vpc" "default"{ + default = true +} + module "blog_vpc" { - source = "terraform-aws-modules/vpc/aws" - version = "2.77.0" + source = "terraform-aws-modules/vpc/aws" name = "dev" cidr = "10.0.0.0/16" - azs = ["eu-north-1a", "eu-north-1b", "eu-north-1c"] - public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] - - enable_dns_hostnames = true + azs = ["eu-north-1a", "eu-north-1b", "eu-north-1c"] + public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] tags = { - Terraform = "true" + Terraform = "true" Environment = "dev" } } -module "blog_sg" { - source = "terraform-aws-modules/security-group/aws" - version = "3.17.0" +resource "aws_instance" "blog" { + ami = data.aws_ami.app_ami.id + instance_type = var.instance_type - name = "blog-sg" - vpc_id = module.blog_vpc.vpc_id + vpc_security_group_ids = [module.blog_sg.security_group_id] - ingress_rules = ["http-80-tcp", "https-443-tcp"] - ingress_cidr_blocks = ["0.0.0.0/0"] + subnet_id = module.blog_vpc.public_subnets[0] - egress_rules = ["all-all"] - egress_cidr_blocks = ["0.0.0.0/0"] + tags = { + Name = "Learning Terraform" + } +} + +module "autoscaling" { + source = "terraform-aws-modules/autoscaling/aws" + version = "9.0.1" + + name ="blog" + min_size = 1 + max_size = 2 + + vpc_zone_identifier = module.blog_vpc.public_subnets + traffic_source_attachments = { + alb = { + traffic_source_arn = element(module.blog_alb.target_group_arns, 0) + type = "elbv2" + } + } + security_groups = [module.blog_sg.security_group_id] + + image_id = data.aws_ami.app_ami.id + instance_type = var.instance_type } module "blog_alb" { source = "terraform-aws-modules/alb/aws" - version = "5.12.0" + version = "9.17.0" - name = "blog-alb" - load_balancer_type = "application" + vpc_id = module.blog_vpc.vpc_id - subnets = module.blog_vpc.public_subnets - vpc_id = module.blog_vpc.vpc_id - security_groups = [module.blog_sg.security_group_id] + load_balancers = { + blog = { + name = "blog-alb" + internal = false + load_balancer_type = "application" + subnets = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] + } + } - target_groups = [ - { - name_prefix = "blog-" - backend_protocol = "HTTP" - backend_port = 80 - target_type = "instance" + target_groups = { + blog = { + name_prefix = "blog-" + protocol = "HTTP" + port = 80 + target_type = "instance" } - ] + } - http_tcp_listeners = [ - { - port = 80 - protocol = "HTTP" - target_group_index = 0 + listeners = { + http = { + port = 80 + protocol = "HTTP" + forward = { + target_group_key = "blog" + } } - ] + } tags = { Environment = "Dev" } } -module "autoscaling" { - source = "terraform-aws-modules/autoscaling/aws" - version = "4.1.0" - - name = "blog-asg" - min_size = 1 - max_size = 2 - desired_capacity = 1 - vpc_zone_identifier = module.blog_vpc.public_subnets - security_groups = [module.blog_sg.security_group_id] +module "blog_sg" { + source = "terraform-aws-modules/security-group/aws" + version = "5.3.0" + name = "blog_new" - launch_template = { - name_prefix = "blog-launch" - image_id = data.aws_ami.app_ami.id - instance_type = "t3.micro" - } + vpc_id = module.blog_vpc.vpc_id - target_group_arns = module.blog_alb.target_group_arns -} + ingress_rules = ["http-80-tcp","https-443-tcp"] + ingress_cidr_blocks = ["0.0.0.0/0"] -output "alb_dns_name" { - value = module.blog_alb.dns_name -} + egress_rules = ["all-all"] + egress_cidr_blocks = ["0.0.0.0/0"] +} \ No newline at end of file From a85a5208c4a935588c7c151ddd6b04577d4c20ce Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:46:49 +0100 Subject: [PATCH 65/89] test lb --- main.tf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.tf b/main.tf index 3d82e51708..17cc60905b 100644 --- a/main.tf +++ b/main.tf @@ -71,7 +71,7 @@ module "blog_alb" { source = "terraform-aws-modules/alb/aws" version = "9.17.0" - vpc_id = module.blog_vpc.vpc_id + vpc_id = module.blog_vpc.vpc_id load_balancers = { blog = { @@ -85,10 +85,10 @@ module "blog_alb" { target_groups = { blog = { - name_prefix = "blog-" - protocol = "HTTP" - port = 80 - target_type = "instance" + name_prefix = "blog-" + protocol = "HTTP" + port = 80 + target_type = "instance" } } From 555df0ecc32856b7cc1e8468c8a44cdeee583bc8 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:49:40 +0100 Subject: [PATCH 66/89] tes lb --- main.tf | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index 17cc60905b..e94eea1a2c 100644 --- a/main.tf +++ b/main.tf @@ -85,10 +85,10 @@ module "blog_alb" { target_groups = { blog = { - name_prefix = "blog-" - protocol = "HTTP" - port = 80 - target_type = "instance" + name_prefix = "blog-" + protocol = "HTTP" + port = 80 + target_type = "instance" } } @@ -104,9 +104,11 @@ module "blog_alb" { tags = { Environment = "Dev" + Project = "Blog" } } + module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.0" From 6c0d3ab926597c893971ee81a8244436ccd49528 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Tue, 8 Jul 2025 00:55:15 +0100 Subject: [PATCH 67/89] revert changes --- main.tf | 60 --------------------------------------------------------- 1 file changed, 60 deletions(-) diff --git a/main.tf b/main.tf index e94eea1a2c..7f7561cc01 100644 --- a/main.tf +++ b/main.tf @@ -46,67 +46,7 @@ resource "aws_instance" "blog" { } } -module "autoscaling" { - source = "terraform-aws-modules/autoscaling/aws" - version = "9.0.1" - - name ="blog" - min_size = 1 - max_size = 2 - - vpc_zone_identifier = module.blog_vpc.public_subnets - traffic_source_attachments = { - alb = { - traffic_source_arn = element(module.blog_alb.target_group_arns, 0) - type = "elbv2" - } - } - security_groups = [module.blog_sg.security_group_id] - - image_id = data.aws_ami.app_ami.id - instance_type = var.instance_type -} - -module "blog_alb" { - source = "terraform-aws-modules/alb/aws" - version = "9.17.0" - - vpc_id = module.blog_vpc.vpc_id - - load_balancers = { - blog = { - name = "blog-alb" - internal = false - load_balancer_type = "application" - subnets = module.blog_vpc.public_subnets - security_groups = [module.blog_sg.security_group_id] - } - } - target_groups = { - blog = { - name_prefix = "blog-" - protocol = "HTTP" - port = 80 - target_type = "instance" - } - } - - listeners = { - http = { - port = 80 - protocol = "HTTP" - forward = { - target_group_key = "blog" - } - } - } - - tags = { - Environment = "Dev" - Project = "Blog" - } -} module "blog_sg" { From 276b4993cac5a23eff5bf091668fa5fcb7b50b34 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 13:24:48 +0100 Subject: [PATCH 68/89] merge --- main.tf | 73 +++++++++++++++++++++++++++++++++++++++++++++++----- variables.tf | 36 ++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 7 deletions(-) diff --git a/main.tf b/main.tf index 7f7561cc01..9079087064 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 = [var.ami_filter.name] } filter { @@ -11,7 +11,7 @@ data "aws_ami" "app_ami" { values = ["hvm"] } - owners = ["979382823631"] # Bitnami + owners = [var.ami_filter.owner] # Bitnami } data "aws_vpc" "default"{ @@ -21,15 +21,15 @@ data "aws_vpc" "default"{ module "blog_vpc" { source = "terraform-aws-modules/vpc/aws" - name = "dev" - cidr = "10.0.0.0/16" + name = var.environment.name + cidr = "${var.environment.network_prefix}.0.0/16" azs = ["eu-north-1a", "eu-north-1b", "eu-north-1c"] - public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.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"] tags = { Terraform = "true" - Environment = "dev" + Environment = var.environment.name } } @@ -46,13 +46,72 @@ resource "aws_instance" "blog" { } } +module "autoscaling" { + source = "terraform-aws-modules/autoscaling/aws" + version = "9.0.1" + + name ="${var.environment.name}-blog" + min_size = var.asg_min_size + max_size = var.asg_max_size + + vpc_zone_identifier = module.blog_vpc.public_subnets + traffic_source_attachments = { + alb = { + traffic_source_arn = element(module.blog_alb.target_group_arns, 0) + type = "elbv2" + } + } + security_groups = [module.blog_sg.security_group_id] + + image_id = data.aws_ami.app_ami.id + instance_type = var.instance_type +} + +module "blog_alb" { + source = "terraform-aws-modules/alb/aws" + version = "9.17.0" + + vpc_id = module.blog_vpc.vpc_id + + load_balancers = { + blog = { + name = "${var.environment.name}-blog-alb" + internal = false + load_balancer_type = "application" + subnets = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] + } + } + target_groups = { + blog = { + name_prefix = "${var.environment.name}-" + protocol = "HTTP" + port = 80 + target_type = "instance" + } + } + + listeners = { + http = { + port = 80 + protocol = "HTTP" + forward = { + target_group_key = "blog" + } + } + } + + tags = { + Environment = var.environment.name + } +} module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.0" - name = "blog_new" + name = "${var.environment.name}-blog" vpc_id = module.blog_vpc.vpc_id diff --git a/variables.tf b/variables.tf index 60856bc925..31c12b078b 100644 --- a/variables.tf +++ b/variables.tf @@ -2,3 +2,39 @@ variable "instance_type" { description = "Type of EC2 instance to provision" default = "t3.nano" } + +variable "ami_filter" { + description = "Name filter and owner for AMI" + + type = object({ + name = string + owner = string + }) + default = { + name = ["bitnami-tomcat-*-x86_64-hvm-ebs-nami"] + owner = ["979382823631"] # Bitnami + } +} + +variable "environment"{ + description = "Development Environment" + + type = object({ + name = string + network_prefix = string + }) + default = { + name = "dev" + network_prefix = "10.0" + } +} + +variable "asg_min_size" { + description = "Minimum number of instances" + default =1 +} + +variable "asg_max_size" { + description = "Maximum number of instances" + default =2 +} \ No newline at end of file From 9046bbfa87642ee98a7dfd50e23c56a805cfc601 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 13:30:56 +0100 Subject: [PATCH 69/89] fix blog_vpc --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 9079087064..edb231c9cf 100644 --- a/main.tf +++ b/main.tf @@ -11,7 +11,7 @@ data "aws_ami" "app_ami" { values = ["hvm"] } - owners = [var.ami_filter.owner] # Bitnami + owners = [var.ami_filter.owner] } data "aws_vpc" "default"{ From b9d154d41295d04459f43146d06ab487542622b4 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 13:31:49 +0100 Subject: [PATCH 70/89] fix var --- variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variables.tf b/variables.tf index 31c12b078b..773009be39 100644 --- a/variables.tf +++ b/variables.tf @@ -11,8 +11,8 @@ variable "ami_filter" { owner = string }) default = { - name = ["bitnami-tomcat-*-x86_64-hvm-ebs-nami"] - owner = ["979382823631"] # Bitnami + name = "bitnami-tomcat-*-x86_64-hvm-ebs-nami" + owner = "979382823631" } } From d5b8185f29afa393289dda00bc99a137c8fe9912 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 13:50:29 +0100 Subject: [PATCH 71/89] fix alb --- main.tf | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.tf b/main.tf index edb231c9cf..d2362b0714 100644 --- a/main.tf +++ b/main.tf @@ -71,18 +71,16 @@ module "blog_alb" { source = "terraform-aws-modules/alb/aws" version = "9.17.0" - vpc_id = module.blog_vpc.vpc_id - - load_balancers = { - blog = { - name = "${var.environment.name}-blog-alb" - internal = false - load_balancer_type = "application" - subnets = module.blog_vpc.public_subnets - security_groups = [module.blog_sg.security_group_id] - } + # Use singular 'load_balancer' as an object + load_balancer = { + name = "${var.environment.name}-blog-alb" + internal = false + load_balancer_type = "application" + subnets = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] } + # Map of target groups target_groups = { blog = { name_prefix = "${var.environment.name}-" @@ -92,6 +90,7 @@ module "blog_alb" { } } + # Map of listener configurations listeners = { http = { port = 80 @@ -108,6 +107,7 @@ module "blog_alb" { } + module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.0" From d99661cdc172276ee5f6a5e3c1e21633fdf3174a Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 13:52:22 +0100 Subject: [PATCH 72/89] fix alb --- main.tf | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/main.tf b/main.tf index d2362b0714..a8e711ea26 100644 --- a/main.tf +++ b/main.tf @@ -71,16 +71,11 @@ module "blog_alb" { source = "terraform-aws-modules/alb/aws" version = "9.17.0" - # Use singular 'load_balancer' as an object - load_balancer = { - name = "${var.environment.name}-blog-alb" - internal = false - load_balancer_type = "application" - subnets = module.blog_vpc.public_subnets - security_groups = [module.blog_sg.security_group_id] - } + name = "${var.environment.name}-blog-alb" + vpc_id = module.blog_vpc.vpc_id + subnets = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] - # Map of target groups target_groups = { blog = { name_prefix = "${var.environment.name}-" @@ -90,6 +85,21 @@ module "blog_alb" { } } + listeners = { + http = { + port = 80 + protocol = "HTTP" + forward = { + target_group_key = "blog" + } + } + } + + tags = { + Environment = var.environment.name + } +} + # Map of listener configurations listeners = { http = { From ef15b32d67e6e1e6e6d7d3cfa3e1b91b6da8b304 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 13:53:51 +0100 Subject: [PATCH 73/89] fix alb --- main.tf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main.tf b/main.tf index a8e711ea26..2f5fb3770d 100644 --- a/main.tf +++ b/main.tf @@ -94,10 +94,6 @@ module "blog_alb" { } } } - - tags = { - Environment = var.environment.name - } } # Map of listener configurations From 66ad222ac7a3d7fdb622351235d8f0f636da1fb5 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 13:55:56 +0100 Subject: [PATCH 74/89] tags issue --- main.tf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 2f5fb3770d..ebae5860ea 100644 --- a/main.tf +++ b/main.tf @@ -94,6 +94,10 @@ module "blog_alb" { } } } + + tags = { + Environment = var.environment.name + } } # Map of listener configurations @@ -110,7 +114,7 @@ module "blog_alb" { tags = { Environment = var.environment.name } -} + From 0407e44c177358019942d72e739c8565ac1f2820 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 13:57:35 +0100 Subject: [PATCH 75/89] alb tags --- main.tf | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/main.tf b/main.tf index ebae5860ea..7fda8824bc 100644 --- a/main.tf +++ b/main.tf @@ -76,15 +76,6 @@ module "blog_alb" { subnets = module.blog_vpc.public_subnets security_groups = [module.blog_sg.security_group_id] - target_groups = { - blog = { - name_prefix = "${var.environment.name}-" - protocol = "HTTP" - port = 80 - target_type = "instance" - } - } - listeners = { http = { port = 80 @@ -95,27 +86,19 @@ module "blog_alb" { } } - tags = { - Environment = var.environment.name - } -} - - # Map of listener configurations - listeners = { - http = { - port = 80 - protocol = "HTTP" - forward = { - target_group_key = "blog" - } + target_groups = { + blog = { + name_prefix = "${var.environment.name}-" + protocol = "HTTP" + port = 80 + target_type = "instance" } } tags = { Environment = var.environment.name } - - +} module "blog_sg" { From c3619fbbd9f3758458f7522377da51ff966a256d Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 14:01:01 +0100 Subject: [PATCH 76/89] fix auto scalling arns --- main.tf | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/main.tf b/main.tf index 7fda8824bc..72381a43fe 100644 --- a/main.tf +++ b/main.tf @@ -49,24 +49,25 @@ resource "aws_instance" "blog" { module "autoscaling" { source = "terraform-aws-modules/autoscaling/aws" version = "9.0.1" - - name ="${var.environment.name}-blog" - min_size = var.asg_min_size - max_size = var.asg_max_size + name = "${var.environment.name}-blog-asg" + min_size = var.asg_min_size + max_size = var.asg_max_size vpc_zone_identifier = module.blog_vpc.public_subnets + security_groups = [module.blog_sg.security_group_id] + traffic_source_attachments = { alb = { - traffic_source_arn = element(module.blog_alb.target_group_arns, 0) + traffic_source_arn = module.blog_alb.target_groups["blog"].arn type = "elbv2" } } - security_groups = [module.blog_sg.security_group_id] - image_id = data.aws_ami.app_ami.id - instance_type = var.instance_type + image_id = data.aws_ami.app_ami.id + instance_type = var.instance_type } + module "blog_alb" { source = "terraform-aws-modules/alb/aws" version = "9.17.0" From a67c3c50337acc6a935fa167391da7ea8ca8134c Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 14:03:08 +0100 Subject: [PATCH 77/89] fix traffic_source_attachments --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 72381a43fe..a468851625 100644 --- a/main.tf +++ b/main.tf @@ -58,8 +58,8 @@ module "autoscaling" { traffic_source_attachments = { alb = { - traffic_source_arn = module.blog_alb.target_groups["blog"].arn - type = "elbv2" + traffic_source_identifier = module.blog_alb.target_groups["blog"].arn + type = "elbv2" } } From e842461efa1b765a3e5f51b8f9344e680d3eab9f Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 14:18:54 +0100 Subject: [PATCH 78/89] fix target_groups --- main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/main.tf b/main.tf index a468851625..82a5a22685 100644 --- a/main.tf +++ b/main.tf @@ -92,7 +92,6 @@ module "blog_alb" { name_prefix = "${var.environment.name}-" protocol = "HTTP" port = 80 - target_type = "instance" } } From d9811f58623e97cae2099a81fb8f26e8efe77567 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 14:24:13 +0100 Subject: [PATCH 79/89] remove target block from alb --- main.tf | 8 -------- 1 file changed, 8 deletions(-) diff --git a/main.tf b/main.tf index 82a5a22685..c7393dfea1 100644 --- a/main.tf +++ b/main.tf @@ -87,14 +87,6 @@ module "blog_alb" { } } - target_groups = { - blog = { - name_prefix = "${var.environment.name}-" - protocol = "HTTP" - port = 80 - } - } - tags = { Environment = var.environment.name } From 74724cb2c62d90bb321dc5b99b9bea81c7dfc040 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 14:34:45 +0100 Subject: [PATCH 80/89] add targets = [] to target_group blog --- main.tf | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.tf b/main.tf index c7393dfea1..6e0f779cd9 100644 --- a/main.tf +++ b/main.tf @@ -87,6 +87,15 @@ module "blog_alb" { } } + target_groups = { + blog = { + name_prefix = "${var.environment.name}-" + protocol = "HTTP" + port = 80 + targets = [] + } + } + tags = { Environment = var.environment.name } From 525d20644de927ace4e3dc9dd80022b3a31313f3 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 14:38:10 +0100 Subject: [PATCH 81/89] remove targets = [] --- main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/main.tf b/main.tf index 6e0f779cd9..82a5a22685 100644 --- a/main.tf +++ b/main.tf @@ -92,7 +92,6 @@ module "blog_alb" { name_prefix = "${var.environment.name}-" protocol = "HTTP" port = 80 - targets = [] } } From 4e860a697b2b567dca6679ee2bac246188991d63 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 14:40:07 +0100 Subject: [PATCH 82/89] added targets = null --- main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/main.tf b/main.tf index 82a5a22685..2967c89ff7 100644 --- a/main.tf +++ b/main.tf @@ -92,6 +92,7 @@ module "blog_alb" { name_prefix = "${var.environment.name}-" protocol = "HTTP" port = 80 + targets = null } } From ece004ec1a60403652738a9d0c4cd776498fda1d Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 14:44:29 +0100 Subject: [PATCH 83/89] fix alb and autoscalling --- main.tf | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/main.tf b/main.tf index 2967c89ff7..829ff593ef 100644 --- a/main.tf +++ b/main.tf @@ -63,8 +63,8 @@ module "autoscaling" { } } - image_id = data.aws_ami.app_ami.id - instance_type = var.instance_type + image_id = data.aws_ami.app_ami.id + instance_type = var.instance_type } @@ -72,10 +72,10 @@ module "blog_alb" { source = "terraform-aws-modules/alb/aws" version = "9.17.0" - name = "${var.environment.name}-blog-alb" - vpc_id = module.blog_vpc.vpc_id - subnets = module.blog_vpc.public_subnets - security_groups = [module.blog_sg.security_group_id] + name = "${var.environment.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 = { http = { @@ -92,7 +92,7 @@ module "blog_alb" { name_prefix = "${var.environment.name}-" protocol = "HTTP" port = 80 - targets = null + # NO 'target_type' or 'targets' here } } @@ -101,7 +101,6 @@ module "blog_alb" { } } - module "blog_sg" { source = "terraform-aws-modules/security-group/aws" version = "5.3.0" From 13e2fc332e682a4caff470fc7d569daa4d4c28fd Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 14:45:52 +0100 Subject: [PATCH 84/89] added create_attachment = false --- main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/main.tf b/main.tf index 829ff593ef..8d9258203e 100644 --- a/main.tf +++ b/main.tf @@ -92,6 +92,7 @@ module "blog_alb" { name_prefix = "${var.environment.name}-" protocol = "HTTP" port = 80 + create_attachment = false # NO 'target_type' or 'targets' here } } From b743d8ff738a86ec8d10a8e0f45a351abc5032c2 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 15:04:51 +0100 Subject: [PATCH 85/89] modulation --- providers.tf => dev/providers.tf | 0 main.tf => modules/blog/main.tf | 0 modules/blog/outputs.tf | 3 +++ variables.tf => modules/blog/variables.tf | 0 outputs.tf | 1 - 5 files changed, 3 insertions(+), 1 deletion(-) rename providers.tf => dev/providers.tf (100%) rename main.tf => modules/blog/main.tf (100%) create mode 100644 modules/blog/outputs.tf rename variables.tf => modules/blog/variables.tf (100%) delete mode 100644 outputs.tf diff --git a/providers.tf b/dev/providers.tf similarity index 100% rename from providers.tf rename to dev/providers.tf diff --git a/main.tf b/modules/blog/main.tf similarity index 100% rename from main.tf rename to modules/blog/main.tf diff --git a/modules/blog/outputs.tf b/modules/blog/outputs.tf new file mode 100644 index 0000000000..379bf9b567 --- /dev/null +++ b/modules/blog/outputs.tf @@ -0,0 +1,3 @@ +output "environment_url" { + value = module.blog_alb.lb_dns_name +} diff --git a/variables.tf b/modules/blog/variables.tf similarity index 100% rename from variables.tf rename to modules/blog/variables.tf diff --git a/outputs.tf b/outputs.tf deleted file mode 100644 index 8b13789179..0000000000 --- a/outputs.tf +++ /dev/null @@ -1 +0,0 @@ - From 198dd50b4ef3fafff2cc6fea077396b4dc530749 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 15:15:06 +0100 Subject: [PATCH 86/89] define dev env --- dev/main.tf | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 dev/main.tf diff --git a/dev/main.tf b/dev/main.tf new file mode 100644 index 0000000000..08a6a8eac2 --- /dev/null +++ b/dev/main.tf @@ -0,0 +1,3 @@ +module "dev" { + source = "../module/blog" +} \ No newline at end of file From 10cdf00558d0757e0d6700fc0108c5c80f2d7738 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 15:15:41 +0100 Subject: [PATCH 87/89] fix source = "../modules/blog" --- dev/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/main.tf b/dev/main.tf index 08a6a8eac2..deb7e7d8be 100644 --- a/dev/main.tf +++ b/dev/main.tf @@ -1,3 +1,3 @@ module "dev" { - source = "../module/blog" + source = "../modules/blog" } \ No newline at end of file From d397afe404a3feb6b6617a6eaf4519f6def499e0 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 15:23:47 +0100 Subject: [PATCH 88/89] fix module.blog_alb.dns_name --- modules/blog/outputs.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/blog/outputs.tf b/modules/blog/outputs.tf index 379bf9b567..a99968f372 100644 --- a/modules/blog/outputs.tf +++ b/modules/blog/outputs.tf @@ -1,3 +1,3 @@ output "environment_url" { - value = module.blog_alb.lb_dns_name + value = module.blog_alb.dns_name } From ee84af5c83037113b91240c655f8f01f155cd136 Mon Sep 17 00:00:00 2001 From: WynandColemanKapsch Date: Sat, 12 Jul 2025 17:10:16 +0100 Subject: [PATCH 89/89] deploy qa --- dev/outputs.tf | 3 +++ qa/main.tf | 8 ++++++++ qa/outputs.tf | 3 +++ qa/providers.tf | 11 +++++++++++ 4 files changed, 25 insertions(+) create mode 100644 dev/outputs.tf create mode 100644 qa/main.tf create mode 100644 qa/outputs.tf create mode 100644 qa/providers.tf diff --git a/dev/outputs.tf b/dev/outputs.tf new file mode 100644 index 0000000000..6fad244faf --- /dev/null +++ b/dev/outputs.tf @@ -0,0 +1,3 @@ +output "environment_url" { + value = module.dev.environment_url +} \ No newline at end of file diff --git a/qa/main.tf b/qa/main.tf new file mode 100644 index 0000000000..d6e8f6c3ff --- /dev/null +++ b/qa/main.tf @@ -0,0 +1,8 @@ +module "qa" { + source = "../modules/blog" + + environment = { + name ="qa" + network_prefix = "10.1" + } +} \ No newline at end of file diff --git a/qa/outputs.tf b/qa/outputs.tf new file mode 100644 index 0000000000..bb99edddeb --- /dev/null +++ b/qa/outputs.tf @@ -0,0 +1,3 @@ +output "environment_url" { + value = module.qa.environment_url +} diff --git a/qa/providers.tf b/qa/providers.tf new file mode 100644 index 0000000000..085443e4bd --- /dev/null +++ b/qa/providers.tf @@ -0,0 +1,11 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + } + } +} + +provider "aws" { + region = "eu-north-1" +}