Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Jacob Bos committed Nov 7, 2022
0 parents commit 8726426
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
36 changes: 36 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
resource "aws_lb" "nlb_app" {
name = format("nlb-%s-lb01-app-%s", var.env_short, var.app_name)
internal = true
load_balancer_type = "network"
subnets = var.lb_subnet_ids
}

resource "aws_lb_listener" "nlb_l_app" {
for_each = var.protocol
load_balancer_arn = aws_lb.nlb_app.arn
port = each.value
protocol = "TCP"

default_action {
type = "forward"
target_group_arn = aws_lb_target_group.tg_app[each.key].arn
}

lifecycle {
create_before_destroy = true
}
}

resource "aws_lb_target_group" "tg_app" {
for_each = var.protocol
name = format("nlb-%s-lb01-app-%s-%s", var.env_short, var.app_name, each.key)
port = each.value
protocol = "TCP"
vpc_id = var.vpc_id
}

resource "aws_autoscaling_attachment" "asg_attachment_app" {
for_each = var.protocol
autoscaling_group_name = var.asg_name
lb_target_group_arn = aws_lb_target_group.tg_app[each.key].arn
}
33 changes: 33 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
variable "env_short" {
type = string
description = "Set the short environment name, i.e. dev, test, acc, prod"
}

variable "app_name" {
type = string
description = "Set the application name i.e. green or blue"
}

variable "lb_subnet_ids" {
type = list(any)
default = null
description = "The list of subnet IDs where the lb will live"
}

variable "protocol" {
type = map(string)
default = null
description = "list of names and ports to be listening on"
}

variable "vpc_id" {
type = string
default = null
description = "Define VPC ID"
}

variable "asg_name" {
type = string
default = null
description = "Set ASG name"
}

0 comments on commit 8726426

Please sign in to comment.