Skip to content

Commit

Permalink
feat: Allow multiple listener rule condition blocks (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorrea committed Mar 8, 2024
1 parent 10e6637 commit 8132110
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/complete-alb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ module "alb" {
query_string = {
key = "weighted"
value = "true"
},
path_pattern = {
values = ["/some/path"]
}
}]
}
Expand Down
32 changes: 31 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ resource "aws_lb_listener_rule" "this" {
}

dynamic "condition" {
for_each = try(each.value.conditions, [])
for_each = [for condition in each.value.conditions : condition if contains(keys(condition), "host_header")]

content {
dynamic "host_header" {
Expand All @@ -370,7 +370,13 @@ resource "aws_lb_listener_rule" "this" {
values = host_header.value.values
}
}
}
}

dynamic "condition" {
for_each = [for condition in each.value.conditions : condition if contains(keys(condition), "http_header")]

content {
dynamic "http_header" {
for_each = try([condition.value.http_header], [])

Expand All @@ -379,23 +385,41 @@ resource "aws_lb_listener_rule" "this" {
values = http_header.value.values
}
}
}
}

dynamic "condition" {
for_each = [for condition in each.value.conditions : condition if contains(keys(condition), "http_request_method")]

content {
dynamic "http_request_method" {
for_each = try([condition.value.http_request_method], [])

content {
values = http_request_method.value.values
}
}
}
}

dynamic "condition" {
for_each = [for condition in each.value.conditions : condition if contains(keys(condition), "path_pattern")]

content {
dynamic "path_pattern" {
for_each = try([condition.value.path_pattern], [])

content {
values = path_pattern.value.values
}
}
}
}

dynamic "condition" {
for_each = [for condition in each.value.conditions : condition if contains(keys(condition), "query_string")]

content {
dynamic "query_string" {
for_each = try([condition.value.query_string], [])

Expand All @@ -404,7 +428,13 @@ resource "aws_lb_listener_rule" "this" {
value = query_string.value.value
}
}
}
}

dynamic "condition" {
for_each = [for condition in each.value.conditions : condition if contains(keys(condition), "source_ip")]

content {
dynamic "source_ip" {
for_each = try([condition.value.source_ip], [])

Expand Down

0 comments on commit 8132110

Please sign in to comment.