Skip to content

Commit

Permalink
feat: Default action forward action type (#269)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Babenko <anton@antonbabenko.com>
  • Loading branch information
michaelact and antonbabenko committed Mar 3, 2023
1 parent 96ea16a commit 4a14075
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
19 changes: 18 additions & 1 deletion examples/complete-alb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -84,7 +101,7 @@ module "alb" {
}
},
{
port = 82
port = 83
protocol = "HTTP"
action_type = "fixed-response"
fixed_response = {
Expand Down
26 changes: 25 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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", {})]
Expand All @@ -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)
}
}
}
}
}
}

Expand Down

0 comments on commit 4a14075

Please sign in to comment.