-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathalb_http_listeners.tf
73 lines (61 loc) · 1.99 KB
/
alb_http_listeners.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
# Create http listener for the loadbalancer if "var.lb_http_listener == true"
resource "aws_lb_listener" "application_loadbalancer_listener_http" {
count = local.create_lb_http_listener
load_balancer_arn = aws_lb.application_loadbalancer.arn
port = var.lb_http_listener_port
protocol = "HTTP"
default_action {
target_group_arn = aws_lb_target_group.tg_http[0].arn
type = "forward"
}
}
# Create http listener rules
resource "aws_lb_listener_rule" "http_host_based_routing" {
count = local.create_lb_http_listener_rules
listener_arn = aws_lb_listener.application_loadbalancer_listener_http[0].arn
action {
type = "forward"
target_group_arn = element(aws_lb_target_group.tg_http.*.arn, count.index)
}
condition {
host_header {
values = lookup(element(var.http_target_group_parameters, count.index), "host_headers")
}
}
lifecycle {
create_before_destroy = true
}
}
# Create http redirect listener for the loadbalancer if "var.lb_http_redirect_listener == true"
resource "aws_lb_listener" "application_loadbalancer_listener_http_redirect" {
count = local.create_lb_http_redirect_listener
load_balancer_arn = aws_lb.application_loadbalancer.arn
port = var.lb_http_redirect_listener_port
protocol = "HTTP"
default_action {
type = "redirect"
redirect {
port = var.lb_http_redirect_to_port
protocol = var.lb_http_redirect_to_protocol
status_code = "HTTP_301"
}
}
}
# Redirect http
# resource "aws_lb_listener_rule" "redirect_http" {
# count = local.create_lb_http_redirect_listener_rules
# listener_arn = aws_lb_listener.application_loadbalancer_listener_http_redirect[0].arn
# action {
# type = "redirect"
# redirect {
# port = "443"
# protocol = "HTTPS"
# status_code = "HTTP_301"
# }
# }
# condition {
# host_header {
# values = ["*.*"]
# }
# }
# }