Skip to content

Commit

Permalink
feat: Add forward group for https listener
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Baranov <[email protected]>
  • Loading branch information
spacedog committed Jul 19, 2023
1 parent cb8e43d commit 959a48d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
17 changes: 17 additions & 0 deletions examples/complete-alb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,23 @@ module "alb" {
user_info_endpoint = "https://${var.domain_name}/user_info"
}
},
{
port = 446
protocol = "HTTPS"
certificate_arn = module.acm.acm_certificate_arn
forward = {
target_groups = [
{
target_group_index = 0
weight = 1
},
{
target_group_index = 1
weight = 0
}
]
}
},
]

extra_ssl_certs = [
Expand Down
26 changes: 25 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,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(keys(lookup(default_action.value, "forward", {}))) == 0 ? 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", {})]
Expand All @@ -735,6 +735,30 @@ resource "aws_lb_listener" "frontend_https" {
}
}

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)
}
}
}
}

# Authentication actions only available with HTTPS listeners
dynamic "authenticate_cognito" {
for_each = length(keys(lookup(default_action.value, "authenticate_cognito", {}))) == 0 ? [] : [lookup(default_action.value, "authenticate_cognito", {})]
Expand Down

0 comments on commit 959a48d

Please sign in to comment.