-
Notifications
You must be signed in to change notification settings - Fork 0
/
load-balnacer.tf
62 lines (53 loc) · 1.51 KB
/
load-balnacer.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
resource "aws_alb" "default" {
name = "${var.app_name}-ALB"
subnets = aws_subnet.public.*.id
load_balancer_type = "application"
security_groups = [aws_security_group.alb.id]
internal = false
tags = {
Name = "${var.app_name}-ALB"
name = "onui"
}
}
resource "aws_lb_listener" "https_forward" {
load_balancer_arn = aws_alb.default.id
port = 443
protocol = "HTTPS"
certificate_arn = aws_acm_certificate.cert.arn
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.http.arn
}
}
resource "aws_lb_target_group" "http" {
vpc_id = aws_vpc.vpc.id
name = "service-alb-tg"
port = 80
protocol = "HTTP"
target_type = "ip"
deregistration_delay = 30
health_check {
interval = 120
path = "/healthcheck"
timeout = 60
matcher = "200"
healthy_threshold = 5
unhealthy_threshold = 5
}
tags = {
Name = "service-alb-tg"
name = "onui"
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_lb_target_group_attachment" "attachment" {
target_group_arn = aws_lb_target_group.http.arn
target_id = aws_instance.ec2.private_ip
port = 80
depends_on = [
aws_lb_target_group.http,
aws_instance.ec2
]
}