diff --git a/main.tf b/main.tf index b937894..1f1cfa5 100644 --- a/main.tf +++ b/main.tf @@ -162,9 +162,17 @@ resource "aws_lb_target_group" "tg" { "instance", ) - stickiness { - type = "lb_cookie" - enabled = false + dynamic "stickiness" { + for_each = lookup( + var.tg_map[element(local.tg_keys, count.index)], + "stickiness_placeholder", + false, + ) ? toset(["build"]) : toset([]) + + content { + enabled = false + type = "lb_cookie" + } } health_check { diff --git a/tests/test1/main.tf b/tests/test1/main.tf index 5e4083f..161e0e5 100644 --- a/tests/test1/main.tf +++ b/tests/test1/main.tf @@ -139,9 +139,10 @@ module "external" { tg_map = { listener1 = { - dereg_delay = 300 - port = 80 - target_type = "instance" + dereg_delay = 300 + port = 80 + target_type = "instance" + stickiness_placeholder = true } } @@ -200,9 +201,10 @@ module "internal" { tg_map = { listener1 = { - dereg_delay = 300 - port = 80 - target_type = "instance" + dereg_delay = 300 + port = 80 + target_type = "instance" + stickiness_placeholder = true } } @@ -233,4 +235,3 @@ module "asg" { module.internal.target_group_arns, ) } - diff --git a/variables.tf b/variables.tf index 9a17b6d..d161dc5 100644 --- a/variables.tf +++ b/variables.tf @@ -145,6 +145,8 @@ tg_map = { "target_type" = "instance" } } + +N.B. if you receive an error `Network Load Balancers do not support Stickiness` then try adding a key to your problem target groups of `stickiness_placeholder = true` */ variable "tg_map" { description = "target group map"