forked from oozou/terraform-aws-pritunl-vpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlb.tf
78 lines (66 loc) · 2.42 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
72
73
74
75
76
77
78
# LoadBalancer Public
resource "aws_lb" "public" {
name = format("%s-public-lb", local.name)
internal = false
load_balancer_type = "network"
subnets = var.public_subnet_ids
tags = merge(
{ Name = format("%s-lb", local.name) },
local.tags
)
}
resource "aws_lb_target_group" "public" {
count = length(local.public_rule)
name = format("%s-public-%s", local.name, count.index)
port = local.public_rule[count.index].port
protocol = local.public_rule[count.index].protocol
vpc_id = var.vpc_id
health_check {
port = lookup(local.public_rule[count.index], "health_check_port", null)
protocol = lookup(local.public_rule[count.index], "health_check_protocol", null)
}
}
resource "aws_lb_listener" "public" {
count = length(local.public_rule)
load_balancer_arn = aws_lb.public.arn
port = local.public_rule[count.index].port
protocol = local.public_rule[count.index].protocol
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.public[count.index].arn
}
}
# LoadBalancer Private
resource "aws_lb" "private" {
count = var.is_create_private_lb ? 1 : 0
name = format("%s-private-lb", local.name)
internal = true
load_balancer_type = "network"
subnets = var.private_subnet_ids
tags = merge(
{ Name = format("%s-lb", local.name) },
local.tags
)
}
resource "aws_lb_target_group" "private" {
count = var.is_create_private_lb ? length(local.private_rule) : 0
name = format("%s-private-%s", local.name, count.index)
preserve_client_ip = false
port = local.private_rule[count.index].port
protocol = local.private_rule[count.index].protocol
vpc_id = var.vpc_id
health_check {
port = lookup(local.private_rule[count.index], "health_check_port", null)
protocol = lookup(local.private_rule[count.index], "health_check_protocol", null)
}
}
resource "aws_lb_listener" "private" {
count = var.is_create_private_lb ? length(local.private_rule) : 0
load_balancer_arn = aws_lb.private[0].arn
port = local.private_rule[count.index].port
protocol = local.private_rule[count.index].protocol
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.private[count.index].arn
}
}