-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprivate-load-balancer.tf
85 lines (71 loc) · 2.49 KB
/
private-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
85
resource "aws_lb" "private_alb" {
name = "sbo-poc-private-alb"
internal = true
load_balancer_type = "application"
security_groups = [aws_security_group.private_alb.id]
subnets = [aws_subnet.private_alb_a.id, aws_subnet.private_alb_b.id]
drop_invalid_header_fields = true
idle_timeout = 300
tags = {
Name = "sbo-poc-private-alb"
}
}
# See https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-update-security-groups.html
resource "aws_security_group" "private_alb" {
name = "Private Load balancer"
vpc_id = module.network.vpc_id
description = "Sec group for the private application load balancer"
tags = {
Name = "alb_private_secgroup"
}
}
resource "aws_vpc_security_group_ingress_rule" "private_alb_allow_3000_internal" {
security_group_id = aws_security_group.private_alb.id
description = "Allow 3000 from internal"
from_port = 3000
to_port = 3000
ip_protocol = "tcp"
cidr_ipv4 = module.network.vpc_cidr_block
tags = {
Name = "private_alb_allow_3000_internal"
}
}
# TODO limit to only the listener ports and health check ports of the instance groups
resource "aws_vpc_security_group_egress_rule" "private_alb_allow_everything_outgoing" {
security_group_id = aws_security_group.private_alb.id
description = "Allow everything outgoing"
ip_protocol = -1
cidr_ipv4 = "0.0.0.0/0"
tags = {
Name = "private_alb_allow_everything_outgoing"
}
}
resource "aws_lb_listener" "private_alb_3000" {
load_balancer_arn = aws_lb.private_alb.arn
port = "3000"
#ts:skip=AC_AWS_0491
protocol = "HTTP" #tfsec:ignore:aws-elb-http-not-used
default_action {
type = "fixed-response"
fixed_response {
content_type = "text/plain"
message_body = "Fixed response content: port 3000 listener"
status_code = "200"
}
}
depends_on = [
aws_lb.private_alb
]
}
output "private_alb_listener_3000_id" {
description = "ID of the listener on port 3000 for the private application load balancer"
value = aws_lb_listener.private_alb_3000.id
}
output "private_alb_listener_3000_arn" {
description = "ARN of the listener on port 3000 for the private application load balancer"
value = aws_lb_listener.private_alb_3000.arn
}
output "private_alb_dns_name" {
description = "DNS name of the private application load balancer"
value = aws_lb.private_alb.dns_name
}