-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Jacob Bos
committed
Nov 7, 2022
0 parents
commit 8726426
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |