From 2d3f9d7546ebe6876c685c6188cdda9412c98618 Mon Sep 17 00:00:00 2001 From: Roberto Mora Date: Mon, 31 Jul 2023 08:24:41 -0600 Subject: [PATCH] fix: target_group_arn should only be specified in listeners if type is forward and traffic needs to be routed to a single target group --- main.tf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 63dc966..5cf13ed 100644 --- a/main.tf +++ b/main.tf @@ -635,7 +635,8 @@ resource "aws_lb_listener" "frontend_http_tcp" { # Defaults to forward action if action_type not specified content { type = lookup(default_action.value, "action_type", "forward") - target_group_arn = contains([null, "", "forward"], lookup(default_action.value, "action_type", "")) ? aws_lb_target_group.main[lookup(default_action.value, "target_group_index", count.index)].id : null + target_group_arn = contains([null, "", "forward"], lookup(default_action.value, "action_type", "")) && length(lookup(lookup(default_action.value, "forward", {}), "target_groups", [])) < 2 ? aws_lb_target_group.main[lookup(default_action.value, "target_group_index", count.index)].id : null + dynamic "redirect" { for_each = length(keys(lookup(default_action.value, "redirect", {}))) == 0 ? [] : [lookup(default_action.value, "redirect", {})] @@ -710,7 +711,7 @@ resource "aws_lb_listener" "frontend_https" { # Defaults to forward action if action_type not specified content { type = lookup(default_action.value, "action_type", "forward") - target_group_arn = contains([null, "", "forward"], lookup(default_action.value, "action_type", "")) ? aws_lb_target_group.main[lookup(default_action.value, "target_group_index", count.index)].id : null + target_group_arn = contains([null, "", "forward"], lookup(default_action.value, "action_type", "")) && length(lookup(lookup(default_action.value, "forward", {}), "target_groups", [])) < 2 ? aws_lb_target_group.main[lookup(default_action.value, "target_group_index", count.index)].id : null dynamic "redirect" { for_each = length(keys(lookup(default_action.value, "redirect", {}))) == 0 ? [] : [lookup(default_action.value, "redirect", {})]