-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlb.tf
71 lines (56 loc) · 1.88 KB
/
lb.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
64
65
66
67
68
69
70
71
resource "aws_lb" "main" {
count = var.nlb_enabled && var.deployment_mode == "ACTIVE_STANDBY_MULTI_AZ" ? 1 : 0
name = var.nlb_name == null ? "${var.broker_name}-nlb" : var.nlb_name
internal = var.nlb_internal
load_balancer_type = "network"
subnets = var.subnet_ids
enable_cross_zone_load_balancing = var.enable_cross_zone_load_balancing
enable_deletion_protection = var.enable_deletion_protection
tags = merge(var.nlb_tags, var.tags)
depends_on = [
aws_mq_broker.main,
]
}
resource "aws_lb_target_group" "main" {
count = var.nlb_enabled && var.deployment_mode == "ACTIVE_STANDBY_MULTI_AZ" ? 1 : 0
name = aws_lb.main[0].name
port = var.nlb_tg_port
protocol = var.nlb_tg_protocol
target_type = "ip"
vpc_id = data.aws_subnet.main[0].vpc_id
health_check {
enabled = true
port = 8162
protocol = "TCP"
interval = 10
healthy_threshold = 3
}
depends_on = [
aws_lb.main,
]
}
resource "aws_lb_target_group_attachment" "main" {
count = (var.nlb_enabled && var.deployment_mode == "ACTIVE_STANDBY_MULTI_AZ") ? length(var.subnet_ids) : 0
target_group_arn = aws_lb_target_group.main[0].arn
target_id = aws_mq_broker.main.instances[count.index]["ip_address"]
port = 8883
depends_on = [
aws_mq_broker.main,
]
}
resource "aws_lb_listener" "main" {
count = var.nlb_enabled && var.deployment_mode == "ACTIVE_STANDBY_MULTI_AZ" ? 1 : 0
load_balancer_arn = aws_lb.main[0].arn
port = "8883"
protocol = "TLS"
certificate_arn = var.nlb_certificate_arn
alpn_policy = "HTTP2Preferred"
ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.main[0].arn
}
depends_on = [
aws_lb.main,
]
}