-
Notifications
You must be signed in to change notification settings - Fork 1
/
nlb.tf
147 lines (131 loc) · 3.9 KB
/
nlb.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Data sources
data "aws_lb" "lb-private" {
arn = aws_lb.lb-private.arn
}
data "aws_lb" "lb-public" {
arn = aws_lb.lb-public.arn
}
data "external" "get_lb_private_ips" {
depends_on = [aws_lb.lb-private]
program = ["python3", "${path.module}/aws-modules/get_nlb_private_ips.py"]
query = {
aws_nlb_name = "lb-priv-${var.cluster_name}-${var.environment}"
aws_vpc_id = var.vpc_id
aws_region = var.region
}
}
# Load balancers
resource "aws_lb" "lb-public" {
name = "lb-public-${var.cluster_name}-${var.environment}"
depends_on = [aws_security_group.sg-lb-to-asg]
load_balancer_type = "network"
internal = false
subnets = [var.subnet_id1, var.subnet_id2]
enable_deletion_protection = false
enable_cross_zone_load_balancing = true
}
resource "aws_lb" "lb-private" {
name = "lb-priv-${var.cluster_name}-${var.environment}"
depends_on = [aws_security_group.sg-lb-to-asg]
load_balancer_type = "network"
internal = true
subnets = [var.subnet_id1, var.subnet_id2]
enable_deletion_protection = false
enable_cross_zone_load_balancing = true
tags = {
description = "lb-priv-${var.cluster_name}-${var.environment}"
}
}
# Load balancer listeners and target groups
resource "aws_lb_listener" "pub-mgmt" {
load_balancer_arn = aws_lb.lb-public.arn
protocol = "TCP"
port = 6443
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.pub-master-mgmt.arn
}
}
resource "aws_lb_listener" "pub-ingress-http" {
load_balancer_arn = aws_lb.lb-public.arn
protocol = "TCP"
port = 80
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.pub-worker-http.arn
}
}
resource "aws_lb_listener" "pub-ingress-https" {
load_balancer_arn = aws_lb.lb-public.arn
protocol = "TCP"
port = 443
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.pub-worker-https.arn
}
}
resource "aws_lb_listener" "priv-mgmt" {
load_balancer_arn = aws_lb.lb-private.arn
protocol = "TCP"
port = 6443
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.priv-master-mgmt.arn
}
}
resource "aws_lb_target_group" "pub-master-mgmt" {
name = "tg-pub-${var.cluster_name}-${var.environment}-master-mgmt"
vpc_id = var.vpc_id
target_type = "instance"
protocol = "TCP"
port = 6443
health_check {
protocol = "TCP"
port = 6443
healthy_threshold = 3
unhealthy_threshold = 3
interval = 10
}
}
resource "aws_lb_target_group" "pub-worker-http" {
name = "tg-pub-${var.cluster_name}-${var.environment}-worker-http"
vpc_id = var.vpc_id
target_type = "instance"
protocol = "TCP"
port = 80
health_check {
protocol = "TCP"
port = 80
healthy_threshold = 3
unhealthy_threshold = 3
interval = 10
}
}
resource "aws_lb_target_group" "pub-worker-https" {
name = "tg-pub-${var.cluster_name}-${var.environment}-worker-https"
vpc_id = var.vpc_id
target_type = "instance"
protocol = "TCP"
port = 443
health_check {
protocol = "TCP"
port = 443
healthy_threshold = 3
unhealthy_threshold = 3
interval = 10
}
}
resource "aws_lb_target_group" "priv-master-mgmt" {
name = "tg-priv-${var.cluster_name}-${var.environment}-master-mgmt"
vpc_id = var.vpc_id
target_type = "instance"
protocol = "TCP"
port = 6443
health_check {
protocol = "TCP"
port = 6443
healthy_threshold = 3
unhealthy_threshold = 3
interval = 10
}
}