-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlb_listener_rule.tf
63 lines (61 loc) · 1.68 KB
/
lb_listener_rule.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
locals {
lb_listener_rule_forwards = { for k, v in var.target_groups_map : aws_lb_target_group.this[k].arn => v }
}
# The first 10 processed rules are free. After that, rule evaluations per second will be considered when calculating the number of LCUs
# If the number of the rules more than 15-20 it can be the main metric for determining the value of LCUs for ALB
resource "aws_lb_listener_rule" "this_single_target" {
for_each = length(var.target_groups_map) == 1 ? toset(var.domain_names) : toset([])
listener_arn = var.lb_listener_arn
action {
type = "forward"
target_group_arn = keys(local.lb_listener_rule_forwards)[0]
}
condition {
host_header {
values = [each.value]
}
}
dynamic "condition" {
for_each = length(var.source_ips) != 0 ? { source_ips = var.source_ips } : {}
content {
source_ip {
values = condition.value
}
}
}
tags = var.tags
}
resource "aws_lb_listener_rule" "this_multi_target" {
for_each = length(var.target_groups_map) > 1 ? toset(var.domain_names) : toset([])
listener_arn = var.lb_listener_arn
action {
type = "forward"
forward {
dynamic "target_group" {
for_each = local.lb_listener_rule_forwards
content {
arn = target_group.key
weight = target_group.value
}
}
stickiness {
duration = 1
enabled = false
}
}
}
condition {
host_header {
values = [each.value]
}
}
dynamic "condition" {
for_each = length(var.source_ips) != 0 ? { source_ips = var.source_ips } : {}
content {
source_ip {
values = condition.value
}
}
}
tags = var.tags
}