-
Notifications
You must be signed in to change notification settings - Fork 61
/
load_balancer.tf
84 lines (71 loc) · 2.62 KB
/
load_balancer.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
#######################################################
# LB section
#######################################################
resource "aws_lb" "bastion-service" {
name = "${var.service_name}-${var.environment_name}"
load_balancer_type = "network"
internal = var.lb_is_internal
subnets = var.subnets_lb
enable_cross_zone_load_balancing = true
tags = var.tags
}
######################################################
# Listener- Port 22 -service only
######################################################
resource "aws_lb_listener" "bastion-service" {
load_balancer_arn = aws_lb.bastion-service.arn
protocol = "TCP"
port = var.bastion_service_port
default_action {
target_group_arn = aws_lb_target_group.bastion-service.arn
type = "forward"
}
}
######################################################
# Listener- Port 2222 - service and host - conditional
######################################################
resource "aws_lb_listener" "bastion-host" {
count = local.hostport_whitelisted ? 1 : 0
load_balancer_arn = aws_lb.bastion-service.arn
protocol = "TCP"
port = "2222"
default_action {
target_group_arn = aws_lb_target_group.bastion-host[0].arn
type = "forward"
}
}
######################################################
# Target group service
#######################################################
resource "aws_lb_target_group" "bastion-service" {
name = "${var.service_name}-${var.environment_name}-${var.bastion_service_port}"
protocol = "TCP"
port = var.bastion_service_port
vpc_id = var.vpc
health_check {
healthy_threshold = var.lb_healthy_threshold
unhealthy_threshold = var.lb_unhealthy_threshold
interval = var.lb_interval
protocol = "TCP"
port = var.lb_healthcheck_port
}
tags = var.tags
}
######################################################
# Target group host - conditional
#######################################################
resource "aws_lb_target_group" "bastion-host" {
count = local.hostport_whitelisted ? 1 : 0
name = "${var.service_name}-${var.environment_name}-2222"
protocol = "TCP"
port = 2222
vpc_id = var.vpc
health_check {
healthy_threshold = var.lb_healthy_threshold
unhealthy_threshold = var.lb_unhealthy_threshold
interval = var.lb_interval
protocol = "TCP"
port = var.lb_healthcheck_port
}
tags = var.tags
}