-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlb-http.tf
45 lines (37 loc) · 1.15 KB
/
lb-http.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
# adds an http listener to the load balancer and allows ingress
# (delete this file if you only want https)
resource "aws_alb_listener" "http" {
# Don't do standard http hosting if redirect is enabled
count = var.do_https_redirect ? 0 : 1
load_balancer_arn = aws_alb.main.id
port = var.lb_port
protocol = var.lb_protocol
default_action {
target_group_arn = aws_alb_target_group.main.id
type = "forward"
}
}
resource "aws_alb_listener" "http_redirect" {
# Redirect http to https when enabled
count = var.do_https_redirect ? 1 : 0
load_balancer_arn = aws_alb.main.id
port = var.lb_port
protocol = "HTTP"
default_action {
type = "redirect"
redirect {
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
}
}
resource "aws_security_group_rule" "ingress_lb_http" {
type = "ingress"
description = var.lb_protocol
from_port = var.lb_port
to_port = var.lb_port
protocol = "tcp"
cidr_blocks = var.custom_default_alb_cidr_blocks
security_group_id = aws_security_group.nsg_lb.id
}