Reputation: 11818
AWS ALB supports rules based on matching both host and path conditions in the same rule.
You can also create rules that combine host-based routing and path-based routing.
I've checked the console and the UI does indeed allow for selecting host and path conditions in the same rule.
Terraform aws_alb_listener_rule seems to support host OR path conditions.
Must be one of path-pattern for path based routing or host-header for host based routing.
Emphasis mine
Is there a way to Terraform an ALB rule that only triggers when both the request hostname and path match some criteria?
Upvotes: 12
Views: 11955
Reputation: 2544
resource "aws_alb_listener_rule" "listener_path_based_test" {
listener_arn = "${aws_alb_listener.listener_prod_https_internal_test.arn}"
action {
type = "forward"
target_group_arn = "${aws_alb_target_group.tg_alb_prod_8080_internal_test.arn}"
}
condition {
field = "path-pattern"
values = ["/some-path/*"]}}
Upvotes: 1
Reputation: 529
You can specify two conditions, which results in an AND of the two conditions:
resource "aws_alb_listener_rule" "host_header_rule" {
condition {
field = "host-header"
values = ["some.host.name"]
}
condition {
field = "path-pattern"
values = ["/some-path/*"]
}
# etc.
}
Upvotes: 16