diff --git a/examples/complete-alb/main.tf b/examples/complete-alb/main.tf index e9a7663..f95cfb6 100644 --- a/examples/complete-alb/main.tf +++ b/examples/complete-alb/main.tf @@ -76,6 +76,23 @@ module "alb" { { port = 81 protocol = "HTTP" + action_type = "forward" + forward = { + target_groups = [ + { + target_group_index = 0 + weight = 100 + }, + { + target_group_index = 1 + weight = 0 + } + ] + } + }, + { + port = 82 + protocol = "HTTP" action_type = "redirect" redirect = { port = "443" @@ -84,7 +101,7 @@ module "alb" { } }, { - port = 82 + port = 83 protocol = "HTTP" action_type = "fixed-response" fixed_response = { diff --git a/main.tf b/main.tf index 7aedd4e..43b87f5 100644 --- a/main.tf +++ b/main.tf @@ -629,7 +629,7 @@ 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, ""], lookup(default_action.value, "action_type", "")) ? 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", {})] @@ -653,6 +653,30 @@ resource "aws_lb_listener" "frontend_http_tcp" { status_code = lookup(fixed_response.value, "status_code", null) } } + + dynamic "forward" { + for_each = length(keys(lookup(default_action.value, "forward", {}))) == 0 ? [] : [lookup(default_action.value, "forward", {})] + + content { + dynamic "target_group" { + for_each = forward.value["target_groups"] + + content { + arn = aws_lb_target_group.main[target_group.value["target_group_index"]].id + weight = lookup(target_group.value, "weight", null) + } + } + + dynamic "stickiness" { + for_each = length(keys(lookup(forward.value, "stickiness", {}))) == 0 ? [] : [lookup(forward.value, "stickiness", {})] + + content { + enabled = lookup(stickiness.value, "enabled", false) + duration = lookup(stickiness.value, "duration", 60) + } + } + } + } } }