Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ resource "aws_alb_target_group" "lb_targets" {
}
}

# Redirect all traffic from the ALB to the target group
# Always exists, acts as a safe dependency wrapper
resource "null_resource" "http_redirect_dep" {
triggers = {
id = (
length(aws_alb_listener.http_redirect) > 0
) ? aws_alb_listener.http_redirect[0].id : "none"
}
}

resource "aws_alb_listener" "lb_listener_ssl" {
count = var.aws_certificate_enabled ? length(local.aws_ecs_lb_port) : 0
load_balancer_arn = "${aws_alb.ecs_lb.id}"
load_balancer_arn = aws_alb.ecs_lb.id
port = local.aws_ecs_lb_port[count.index]
# https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html
ssl_policy = var.aws_ecs_lb_ssl_policy
Expand All @@ -72,26 +80,24 @@ resource "aws_alb_listener" "lb_listener_ssl" {
type = "forward"
}
lifecycle {
replace_triggered_by = [ aws_alb_listener.http_redirect ]
replace_triggered_by = [null_resource.http_redirect_dep.id]
}
}

resource "aws_alb_listener" "lb_listener" {
count = var.aws_certificate_enabled ? 0 : length(local.aws_ecs_lb_port)
load_balancer_arn = "${aws_alb.ecs_lb.id}"
load_balancer_arn = aws_alb.ecs_lb.id
port = local.aws_ecs_lb_port[count.index]
protocol = "HTTP"
default_action {
target_group_arn = aws_alb_target_group.lb_targets[count.index].id
type = "forward"
}
lifecycle {
replace_triggered_by = [ aws_alb_listener.http_redirect ]
replace_triggered_by = [null_resource.http_redirect_dep.id]
}
}



resource "aws_alb_listener_rule" "redirect_based_on_path" {
for_each = { for idx, path in local.aws_ecs_lb_container_path : idx => path if length(path) > 0 }
listener_arn = var.aws_certificate_enabled ? aws_alb_listener.lb_listener_ssl[0].arn : aws_alb_listener.lb_listener[0].arn
Expand Down