Skip to content

Commit 6b5f0d4

Browse files
feat: Support weight in forward action (#224)
1 parent eac30ff commit 6b5f0d4

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

examples/complete-alb/main.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,35 @@ module "alb" {
246246
}]
247247
}]
248248
},
249+
{
250+
https_listener_index = 0
251+
priority = 4
252+
253+
actions = [{
254+
type = "weighted-forward"
255+
target_groups = [
256+
{
257+
target_group_index = 1
258+
weight = 2
259+
},
260+
{
261+
target_group_index = 0
262+
weight = 1
263+
}
264+
]
265+
stickiness = {
266+
enabled = true
267+
duration = 3600
268+
}
269+
}]
270+
271+
conditions = [{
272+
query_strings = [{
273+
key = "weighted"
274+
value = "true"
275+
}]
276+
}]
277+
},
249278
{
250279
https_listener_index = 0
251280
priority = 5000

main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,37 @@ resource "aws_lb_listener_rule" "https_listener_rule" {
247247
}
248248
}
249249

250+
# weighted forward actions
251+
dynamic "action" {
252+
for_each = [
253+
for action_rule in var.https_listener_rules[count.index].actions :
254+
action_rule
255+
if action_rule.type == "weighted-forward"
256+
]
257+
258+
content {
259+
type = "forward"
260+
forward {
261+
dynamic "target_group" {
262+
for_each = action.value["target_groups"]
263+
264+
content {
265+
arn = aws_lb_target_group.main[target_group.value["target_group_index"]].id
266+
weight = target_group.value["weight"]
267+
}
268+
}
269+
dynamic "stickiness" {
270+
for_each = [lookup(action.value, "stickiness", {})]
271+
272+
content {
273+
enabled = try(stickiness.value["enabled"], false)
274+
duration = try(stickiness.value["duration"], 1)
275+
}
276+
}
277+
}
278+
}
279+
}
280+
250281
# Path Pattern condition
251282
dynamic "condition" {
252283
for_each = [

variables.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ variable "http_tcp_listeners_tags" {
178178
default = {}
179179
}
180180

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

0 commit comments

Comments
 (0)