Skip to content

Commit

Permalink
feat: Support weight in forward action (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbricepalo authored Nov 19, 2021
1 parent eac30ff commit 6b5f0d4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
29 changes: 29 additions & 0 deletions examples/complete-alb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,35 @@ module "alb" {
}]
}]
},
{
https_listener_index = 0
priority = 4

actions = [{
type = "weighted-forward"
target_groups = [
{
target_group_index = 1
weight = 2
},
{
target_group_index = 0
weight = 1
}
]
stickiness = {
enabled = true
duration = 3600
}
}]

conditions = [{
query_strings = [{
key = "weighted"
value = "true"
}]
}]
},
{
https_listener_index = 0
priority = 5000
Expand Down
31 changes: 31 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,37 @@ resource "aws_lb_listener_rule" "https_listener_rule" {
}
}

# weighted forward actions
dynamic "action" {
for_each = [
for action_rule in var.https_listener_rules[count.index].actions :
action_rule
if action_rule.type == "weighted-forward"
]

content {
type = "forward"
forward {
dynamic "target_group" {
for_each = action.value["target_groups"]

content {
arn = aws_lb_target_group.main[target_group.value["target_group_index"]].id
weight = target_group.value["weight"]
}
}
dynamic "stickiness" {
for_each = [lookup(action.value, "stickiness", {})]

content {
enabled = try(stickiness.value["enabled"], false)
duration = try(stickiness.value["duration"], 1)
}
}
}
}
}

# Path Pattern condition
dynamic "condition" {
for_each = [
Expand Down
1 change: 0 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ variable "http_tcp_listeners_tags" {
default = {}
}


variable "security_groups" {
description = "The security groups to attach to the load balancer. e.g. [\"sg-edcd9784\",\"sg-edcd9785\"]"
type = list(string)
Expand Down

0 comments on commit 6b5f0d4

Please sign in to comment.