Skip to content
Open

Merge #291

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
98455a9
initial commit
WynandColemanKapsch Jul 6, 2025
fc6017e
Update main.tf
WynandColemanKapsch Jul 6, 2025
977a98b
Update outputs.tf
WynandColemanKapsch Jul 6, 2025
ae95d6a
Update outputs.tf
WynandColemanKapsch Jul 6, 2025
1904636
Create Security Group
WynandColemanKapsch Jul 6, 2025
8e12a83
Fixes CIDR for security rules
WynandColemanKapsch Jul 6, 2025
764eaa6
fixed vpc_security_group_ids
WynandColemanKapsch Jul 6, 2025
de01913
fixed aws_security_group.blog.id
WynandColemanKapsch Jul 6, 2025
608fa24
fixed security group id for rules
WynandColemanKapsch Jul 6, 2025
5876dc1
new security group using module
WynandColemanKapsch Jul 6, 2025
3073e99
fixed module sg ingress_rules array with correct https vars
WynandColemanKapsch Jul 6, 2025
b1cccb9
scale 0
WynandColemanKapsch Jul 6, 2025
ce1d2eb
scale 0
WynandColemanKapsch Jul 6, 2025
14e18bc
scale 0
WynandColemanKapsch Jul 6, 2025
5fff736
scale removed
WynandColemanKapsch Jul 6, 2025
07ad666
create new dev vpc
WynandColemanKapsch Jul 7, 2025
aca2f4b
fix instance subnet_id = module.blog_vpc.public_subnets[0]
WynandColemanKapsch Jul 7, 2025
a8a2ce9
fix azs
WynandColemanKapsch Jul 7, 2025
5cd5c9c
2nd fix azs
WynandColemanKapsch Jul 7, 2025
c8eea47
fix provider region eu-north-1
WynandColemanKapsch Jul 7, 2025
36977a9
fix azs azs = ["eu-north-1a", "eu-north-1b", "eu-north-1c"]
WynandColemanKapsch Jul 7, 2025
a1b6b07
removed aws_security_group.blog as its not needed due to module "blog…
WynandColemanKapsch Jul 7, 2025
6e683f1
loadbalancer
WynandColemanKapsch Jul 7, 2025
f21b9f3
fix
WynandColemanKapsch Jul 7, 2025
00ae9d8
fix protocol = "HTTP"
WynandColemanKapsch Jul 7, 2025
32ad6e5
changed http_tcp_listeners to array
WynandColemanKapsch Jul 7, 2025
3317ea2
fix module "alb"
WynandColemanKapsch Jul 7, 2025
a186fa4
fix target_id = aws_instance.blog.id
WynandColemanKapsch Jul 7, 2025
c875359
test lb
WynandColemanKapsch Jul 7, 2025
36dafc3
test lb
WynandColemanKapsch Jul 7, 2025
2c8aee4
test lb
WynandColemanKapsch Jul 7, 2025
7e8a05e
tes lb
WynandColemanKapsch Jul 7, 2025
90c453d
test lb
WynandColemanKapsch Jul 7, 2025
8e6e552
test lb
WynandColemanKapsch Jul 7, 2025
cdc90ce
test lb
WynandColemanKapsch Jul 7, 2025
5b4401a
tes lb
WynandColemanKapsch Jul 7, 2025
c3fe5f9
test lb
WynandColemanKapsch Jul 7, 2025
ed48d40
test lb
WynandColemanKapsch Jul 7, 2025
c72ecc1
test lb
WynandColemanKapsch Jul 7, 2025
612d62c
test
WynandColemanKapsch Jul 7, 2025
1196bf0
test lb
WynandColemanKapsch Jul 7, 2025
9307b5c
test lb
WynandColemanKapsch Jul 7, 2025
ecd86d2
test lb
WynandColemanKapsch Jul 7, 2025
5f5d2fc
test lb
WynandColemanKapsch Jul 7, 2025
17b0cbc
test lb
WynandColemanKapsch Jul 7, 2025
469489a
tes lb
WynandColemanKapsch Jul 7, 2025
b286a23
test lb
WynandColemanKapsch Jul 7, 2025
bd29cae
scalling
WynandColemanKapsch Jul 7, 2025
eff8477
test scalling
WynandColemanKapsch Jul 7, 2025
ad273ca
test scalling
WynandColemanKapsch Jul 7, 2025
d66b9dd
test scalling
WynandColemanKapsch Jul 7, 2025
28b105f
test autoscalling
WynandColemanKapsch Jul 7, 2025
dfbf4fd
test scalling
WynandColemanKapsch Jul 7, 2025
ffb6572
test scalling
WynandColemanKapsch Jul 7, 2025
1daeeff
test scalling
WynandColemanKapsch Jul 7, 2025
a7ba206
test scalling
WynandColemanKapsch Jul 7, 2025
fdd11f9
test scalling
WynandColemanKapsch Jul 7, 2025
01c6e5e
test scalling
WynandColemanKapsch Jul 7, 2025
2b93176
test scalling
WynandColemanKapsch Jul 7, 2025
b7b13b3
fix lb for autoscalling
WynandColemanKapsch Jul 7, 2025
40a072e
tes new lb
WynandColemanKapsch Jul 7, 2025
c9327f0
test lb with scalling
WynandColemanKapsch Jul 7, 2025
de2bacd
test lb with scalling
WynandColemanKapsch Jul 7, 2025
b82bbd2
test lb scalling
WynandColemanKapsch Jul 7, 2025
a85a520
test lb
WynandColemanKapsch Jul 7, 2025
555df0e
tes lb
WynandColemanKapsch Jul 7, 2025
6c0d3ab
revert changes
WynandColemanKapsch Jul 7, 2025
276b499
merge
WynandColemanKapsch Jul 12, 2025
9046bbf
fix blog_vpc
WynandColemanKapsch Jul 12, 2025
b9d154d
fix var
WynandColemanKapsch Jul 12, 2025
d5b8185
fix alb
WynandColemanKapsch Jul 12, 2025
d99661c
fix alb
WynandColemanKapsch Jul 12, 2025
ef15b32
fix alb
WynandColemanKapsch Jul 12, 2025
66ad222
tags issue
WynandColemanKapsch Jul 12, 2025
0407e44
alb tags
WynandColemanKapsch Jul 12, 2025
c3619fb
fix auto scalling arns
WynandColemanKapsch Jul 12, 2025
a67c3c5
fix traffic_source_attachments
WynandColemanKapsch Jul 12, 2025
e842461
fix target_groups
WynandColemanKapsch Jul 12, 2025
d9811f5
remove target block from alb
WynandColemanKapsch Jul 12, 2025
74724cb
add targets = [] to target_group blog
WynandColemanKapsch Jul 12, 2025
525d206
remove targets = []
WynandColemanKapsch Jul 12, 2025
4e860a6
added targets = null
WynandColemanKapsch Jul 12, 2025
ece004e
fix alb and autoscalling
WynandColemanKapsch Jul 12, 2025
13e2fc3
added create_attachment = false
WynandColemanKapsch Jul 12, 2025
b743d8f
modulation
WynandColemanKapsch Jul 12, 2025
198dd50
define dev env
WynandColemanKapsch Jul 12, 2025
10cdf00
fix source = "../modules/blog"
WynandColemanKapsch Jul 12, 2025
d397afe
fix module.blog_alb.dns_name
WynandColemanKapsch Jul 12, 2025
ee84af5
deploy qa
WynandColemanKapsch Jul 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dev/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module "dev" {
source = "../modules/blog"
}
3 changes: 3 additions & 0 deletions dev/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "environment_url" {
value = module.dev.environment_url
}
2 changes: 1 addition & 1 deletion providers.tf → dev/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ terraform {
}

provider "aws" {
region = "us-west-2"
region = "eu-north-1"
}
24 changes: 0 additions & 24 deletions main.tf

This file was deleted.

117 changes: 117 additions & 0 deletions modules/blog/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
data "aws_ami" "app_ami" {
most_recent = true

filter {
name = "name"
values = [var.ami_filter.name]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = [var.ami_filter.owner]
}

data "aws_vpc" "default"{
default = true
}

module "blog_vpc" {
source = "terraform-aws-modules/vpc/aws"

name = var.environment.name
cidr = "${var.environment.network_prefix}.0.0/16"

azs = ["eu-north-1a", "eu-north-1b", "eu-north-1c"]
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 = var.environment.name
}
}

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 "autoscaling" {
source = "terraform-aws-modules/autoscaling/aws"
version = "9.0.1"

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_identifier = module.blog_alb.target_groups["blog"].arn
type = "elbv2"
}
}

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"

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 = {
port = 80
protocol = "HTTP"
forward = {
target_group_key = "blog"
}
}
}

target_groups = {
blog = {
name_prefix = "${var.environment.name}-"
protocol = "HTTP"
port = 80
create_attachment = false
# NO 'target_type' or 'targets' here
}
}

tags = {
Environment = var.environment.name
}
}

module "blog_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.3.0"
name = "${var.environment.name}-blog"

vpc_id = module.blog_vpc.vpc_id

ingress_rules = ["http-80-tcp","https-443-tcp"]
ingress_cidr_blocks = ["0.0.0.0/0"]

egress_rules = ["all-all"]
egress_cidr_blocks = ["0.0.0.0/0"]
}
3 changes: 3 additions & 0 deletions modules/blog/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "environment_url" {
value = module.blog_alb.dns_name
}
40 changes: 40 additions & 0 deletions modules/blog/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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"
}
}

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
}
7 changes: 0 additions & 7 deletions outputs.tf

This file was deleted.

8 changes: 8 additions & 0 deletions qa/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module "qa" {
source = "../modules/blog"

environment = {
name ="qa"
network_prefix = "10.1"
}
}
3 changes: 3 additions & 0 deletions qa/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "environment_url" {
value = module.qa.environment_url
}
11 changes: 11 additions & 0 deletions qa/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}

provider "aws" {
region = "eu-north-1"
}
4 changes: 0 additions & 4 deletions variables.tf

This file was deleted.