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 2 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
25 changes: 25 additions & 0 deletions examples/complete-alb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,31 @@ 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
}
]
}]

conditions = [{
query_strings = [{
key = "weighted"
value = "true"
}]
}]
},
{
https_listener_index = 0
priority = 5000
Expand Down
23 changes: 23 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,29 @@ 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dynamic target_group {
dynamic "target_group" {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, could you make sure that the example works when values in weight change?

Currently, terraform apply fails after changing it with this error:

│ Error: Error modifying LB Listener Rule: ValidationError: Target group stickiness duration must be between 1 and 604800 seconds

Here is a related bug - hashicorp/terraform-provider-aws#15144

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @antonbabenko. I updated my PR and added the stickiness block.

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"]
}
}
}
}
}

# Path Pattern condition
dynamic "condition" {
for_each = [
Expand Down