Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support weight in forward action #224

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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