1
+ resource "aws_lb" "this_nlb" {
2
+ name = " observers-network-lb"
3
+ internal = false
4
+ load_balancer_type = " network"
5
+ subnets = module. this_vpc . public_subnets
6
+
7
+ enable_cross_zone_load_balancing = true
8
+ # enable_deletion_protection = true
9
+
10
+ tags = {
11
+ Name = " Observers NLB"
12
+ }
13
+ }
14
+
15
+ locals {
16
+ tls_cert_arn = var. enable_tls ? aws_acm_certificate_validation. this_acm_cert_validation [0 ]. certificate_arn : " "
17
+ ssl_policy = " ELBSecurityPolicy-TLS13-1-2-2021-06" # TLS 1.3 (recommended)
18
+ }
19
+
20
+ resource "aws_lb_listener" "rest" {
21
+ count = local. enable_tls ? 0 : 1
22
+
23
+ load_balancer_arn = aws_lb. this_nlb . arn
24
+ port = " 80"
25
+ protocol = " TCP"
26
+
27
+ default_action {
28
+ type = " forward"
29
+ target_group_arn = aws_lb_target_group. rest . arn
30
+ }
31
+ }
32
+
33
+ resource "aws_lb_listener" "grpc" {
34
+ count = local. enable_tls ? 0 : 1
35
+
36
+ load_balancer_arn = aws_lb. this_nlb . arn
37
+ port = " 9090"
38
+ protocol = " TCP"
39
+
40
+ default_action {
41
+ type = " forward"
42
+ target_group_arn = aws_lb_target_group. grpc . arn
43
+ }
44
+ }
45
+
46
+ resource "aws_lb_listener" "rpc" {
47
+ count = local. enable_tls ? 0 : 1
48
+
49
+ load_balancer_arn = aws_lb. this_nlb . arn
50
+ port = " 8080"
51
+ protocol = " TCP"
52
+
53
+ default_action {
54
+ type = " forward"
55
+ target_group_arn = aws_lb_target_group. rpc . arn
56
+ }
57
+ }
58
+
59
+ resource "aws_lb_listener" "tls_rest" {
60
+ count = local. enable_tls ? 1 : 0
61
+
62
+ load_balancer_arn = aws_lb. this_nlb . arn
63
+ port = " 443"
64
+ protocol = " TLS"
65
+ certificate_arn = local. tls_cert_arn
66
+ ssl_policy = local. ssl_policy
67
+
68
+ default_action {
69
+ type = " forward"
70
+ target_group_arn = aws_lb_target_group. rest . arn
71
+ }
72
+
73
+ depends_on = [
74
+ aws_acm_certificate_validation . this_acm_cert_validation [0 ]
75
+ ]
76
+ }
77
+
78
+ resource "aws_lb_listener" "tls_grpc" {
79
+ count = local. enable_tls ? 1 : 0
80
+
81
+ load_balancer_arn = aws_lb. this_nlb . arn
82
+ port = " 8443"
83
+ protocol = " TLS"
84
+ certificate_arn = local. tls_cert_arn
85
+ ssl_policy = local. ssl_policy
86
+
87
+ default_action {
88
+ type = " forward"
89
+ target_group_arn = aws_lb_target_group. grpc . arn
90
+ }
91
+
92
+ depends_on = [
93
+ aws_acm_certificate_validation . this_acm_cert_validation [0 ]
94
+ ]
95
+ }
96
+
97
+ resource "aws_lb_listener" "tls_rpc" {
98
+ count = local. enable_tls ? 1 : 0
99
+
100
+ load_balancer_arn = aws_lb. this_nlb . arn
101
+ port = " 26657"
102
+ protocol = " TLS"
103
+ certificate_arn = local. tls_cert_arn
104
+ ssl_policy = local. ssl_policy
105
+
106
+ default_action {
107
+ type = " forward"
108
+ target_group_arn = aws_lb_target_group. rpc . arn
109
+ }
110
+
111
+ depends_on = [
112
+ aws_acm_certificate_validation . this_acm_cert_validation [0 ]
113
+ ]
114
+ }
115
+
116
+ resource "aws_lb_target_group" "rest" {
117
+ name = " observers-rest-target-group"
118
+ port = 1317
119
+ protocol = " TCP"
120
+ vpc_id = module. this_vpc . vpc_id
121
+ preserve_client_ip = false
122
+ }
123
+
124
+ resource "aws_lb_target_group" "grpc" {
125
+ name = " observers-grpc-target-group"
126
+ port = 9090
127
+ protocol = " TCP"
128
+ vpc_id = module. this_vpc . vpc_id
129
+ preserve_client_ip = false
130
+ }
131
+
132
+ resource "aws_lb_target_group" "rpc" {
133
+ name = " observers-rpc-target-group"
134
+ port = 26657
135
+ protocol = " TCP"
136
+ vpc_id = module. this_vpc . vpc_id
137
+ preserve_client_ip = false
138
+ }
139
+
140
+ resource "aws_lb_target_group_attachment" "rest_targets" {
141
+ count = length (aws_instance. this_nodes )
142
+
143
+ target_group_arn = aws_lb_target_group. rest . arn
144
+ target_id = aws_instance. this_nodes [count . index ]. id
145
+ port = 80
146
+ }
147
+
148
+ resource "aws_lb_target_group_attachment" "grpc_targets" {
149
+ count = length (aws_instance. this_nodes )
150
+
151
+ target_group_arn = aws_lb_target_group. grpc . arn
152
+ target_id = aws_instance. this_nodes [count . index ]. id
153
+ port = 9090
154
+ }
155
+
156
+ resource "aws_lb_target_group_attachment" "rpc_targets" {
157
+ count = length (aws_instance. this_nodes )
158
+
159
+ target_group_arn = aws_lb_target_group. rpc . arn
160
+ target_id = aws_instance. this_nodes [count . index ]. id
161
+ port = 26657
162
+ }
0 commit comments