Skip to content
27 changes: 27 additions & 0 deletions infra/modules/service/load_balancer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,33 @@ resource "aws_lb_listener" "alb_listener_http" {
}
}

resource "aws_lb_listener_rule" "http_to_https_redirect" {
count = var.certificate_arn != null ? 1 : 0

listener_arn = aws_lb_listener.alb_listener_http.arn
priority = 50

action {
type = "redirect"
redirect {
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
host = "#{host}"
path = "/#{path}"
query = "#{query}"
}
}
condition {
path_pattern {
values = ["/*"]
}
}
}

resource "aws_lb_listener_rule" "app_http_forward" {
count = var.certificate_arn == null ? 1 : 0

listener_arn = aws_lb_listener.alb_listener_http.arn
priority = 100

Expand Down Expand Up @@ -93,6 +119,7 @@ resource "aws_lb_listener" "alb_listener_https" {
}
}


resource "aws_lb_listener_rule" "app_https_forward" {
count = var.certificate_arn != null ? 1 : 0

Expand Down
Loading