Skip to content

Commit 4a14075

Browse files
feat: Default action forward action type (#269)
Co-authored-by: Anton Babenko <[email protected]>
1 parent 96ea16a commit 4a14075

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

examples/complete-alb/main.tf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ module "alb" {
7676
{
7777
port = 81
7878
protocol = "HTTP"
79+
action_type = "forward"
80+
forward = {
81+
target_groups = [
82+
{
83+
target_group_index = 0
84+
weight = 100
85+
},
86+
{
87+
target_group_index = 1
88+
weight = 0
89+
}
90+
]
91+
}
92+
},
93+
{
94+
port = 82
95+
protocol = "HTTP"
7996
action_type = "redirect"
8097
redirect = {
8198
port = "443"
@@ -84,7 +101,7 @@ module "alb" {
84101
}
85102
},
86103
{
87-
port = 82
104+
port = 83
88105
protocol = "HTTP"
89106
action_type = "fixed-response"
90107
fixed_response = {

main.tf

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ resource "aws_lb_listener" "frontend_http_tcp" {
629629
# Defaults to forward action if action_type not specified
630630
content {
631631
type = lookup(default_action.value, "action_type", "forward")
632-
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
632+
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
633633

634634
dynamic "redirect" {
635635
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" {
653653
status_code = lookup(fixed_response.value, "status_code", null)
654654
}
655655
}
656+
657+
dynamic "forward" {
658+
for_each = length(keys(lookup(default_action.value, "forward", {}))) == 0 ? [] : [lookup(default_action.value, "forward", {})]
659+
660+
content {
661+
dynamic "target_group" {
662+
for_each = forward.value["target_groups"]
663+
664+
content {
665+
arn = aws_lb_target_group.main[target_group.value["target_group_index"]].id
666+
weight = lookup(target_group.value, "weight", null)
667+
}
668+
}
669+
670+
dynamic "stickiness" {
671+
for_each = length(keys(lookup(forward.value, "stickiness", {}))) == 0 ? [] : [lookup(forward.value, "stickiness", {})]
672+
673+
content {
674+
enabled = lookup(stickiness.value, "enabled", false)
675+
duration = lookup(stickiness.value, "duration", 60)
676+
}
677+
}
678+
}
679+
}
656680
}
657681
}
658682

0 commit comments

Comments
 (0)