Skip to content

Commit fd3fcef

Browse files
committed
Fix with/without redirect
1 parent bb482dd commit fd3fcef

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

operations/deployment/terraform/modules/aws/ecs/aws_ecs_networking.tf

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,18 @@ resource "aws_alb_listener_rule" "redirect_based_on_path" {
124124
}
125125

126126
resource "aws_alb_listener" "http_redirect" {
127-
count = var.aws_ecs_lb_redirect_enable && !contains(local.aws_ecs_lb_port,80) ? 1 : 0
127+
count = var.aws_ecs_lb_redirect_enable && !contains(local.aws_ecs_lb_port,80) && var.aws_certificate_enabled ? 1 : 0
128128
load_balancer_arn = aws_alb.ecs_lb[0].id
129129
port = "80"
130130
protocol = "HTTP"
131131

132-
133132
default_action {
134-
type = var.aws_certificate_enabled ? "redirect" : "forward"
135-
target_group_arn = var.aws_certificate_enabled ? null : aws_alb_target_group.lb_targets[0].id
136-
137-
dynamic "redirect" {
138-
for_each = var.aws_certificate_enabled ? [1] : [0]
139-
content {
140-
port = 443
141-
protocol = "HTTPS"
142-
status_code = "HTTP_301"
143-
}
133+
type = "redirect"
134+
135+
redirect {
136+
port = "443"
137+
protocol = "HTTPS"
138+
status_code = "HTTP_301"
144139
}
145140
}
146141
depends_on = [
@@ -149,6 +144,22 @@ resource "aws_alb_listener" "http_redirect" {
149144
]
150145
}
151146

147+
resource "aws_alb_listener" "http_forward" {
148+
count = var.aws_ecs_lb_redirect_enable && !contains(local.aws_ecs_lb_port,80) && !var.aws_certificate_enabled ? 1 : 0
149+
load_balancer_arn = aws_alb.ecs_lb[0].id
150+
port = "80"
151+
protocol = "HTTP"
152+
153+
default_action {
154+
type = "forward"
155+
target_group_arn = aws_alb_target_group.lb_targets[0].id
156+
}
157+
depends_on = [
158+
aws_alb.ecs_lb,
159+
aws_alb_target_group.lb_targets
160+
]
161+
}
162+
152163
resource "aws_security_group_rule" "incoming_alb_http" {
153164
count = length(aws_alb_listener.http_redirect)
154165
type = "ingress"

0 commit comments

Comments
 (0)