-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalb.tf
56 lines (49 loc) · 1.32 KB
/
alb.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
# alb.tf
resource "aws_lb" "web_app_lb" {
name = "web-app-lb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.lb_sg.id]
subnets = aws_subnet.public.*.id
enable_deletion_protection = false
}
resource "aws_lb_target_group" "web_app_tg" {
name = "web-app-tg"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.main.id
target_type = "instance"
health_check {
path = "/health/"
port = "80"
protocol = "HTTP"
interval = 30
timeout = 5
healthy_threshold = 2
unhealthy_threshold = 2
}
}
resource "aws_lb_listener" "https" {
load_balancer_arn = aws_lb.web_app_lb.arn
port = "443"
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-2016-08"
certificate_arn = var.ssl_certificate_arn
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.web_app_tg.arn
}
}
resource "aws_lb_listener" "http" {
load_balancer_arn = aws_lb.web_app_lb.arn
port = "80"
protocol = "HTTP"
default_action {
type = "redirect"
redirect {
protocol = "HTTPS"
port = "443"
status_code = "HTTP_301"
}
}
}