Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions _outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ output "alb_listener_https_arn" {
value = aws_lb_listener.ecs_https.*.arn
}

output "test_traffic_route_listener_arn" {
value = aws_lb_listener.ecs_test_https.*.arn
}

output "ecs_nodes_secgrp_id" {
value = aws_security_group.ecs_nodes.id
}
Expand Down
56 changes: 54 additions & 2 deletions alb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,72 @@ resource "aws_lb_listener" "ecs_http_redirect" {
}
}

resource "aws_lb_listener" "ecs_test_https" {
count = var.alb ? 1 : 0

load_balancer_arn = aws_lb.ecs[0].arn
port = "8443"
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-2016-08"
certificate_arn = var.certificate_arn

default_action {
type = "forward"
#target_group_arn = aws_lb_target_group.ecs_replacement_https[0].arn
target_group_arn = aws_lb_target_group.ecs_default_https[0].arn
}
}

resource "aws_lb_listener" "ecs_test_http_redirect" {
count = var.alb ? 1 : 0

load_balancer_arn = aws_lb.ecs[0].arn
port = "8080"
protocol = "HTTP"

default_action {
type = "redirect"

redirect {
port = "8443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
}
}

# Generate a random string to add it to the name of the Target Group
resource "random_string" "alb_prefix" {
length = 4
upper = false
special = false
}

resource "aws_lb_target_group" "ecs_default_http" {
count = var.alb ? 1 : 0

name = "ecs-${var.name}-default-http"
name = substr("ecs-${var.name}-default-http-${random_string.alb_prefix.result}", 0, 32)
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id

lifecycle {
create_before_destroy = true
}
}

resource "aws_lb_target_group" "ecs_default_https" {
count = var.alb ? 1 : 0

name = "ecs-${var.name}-default-https"
name = substr("ecs-${var.name}-default-https-${random_string.alb_prefix.result}", 0, 32)
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id

lifecycle {
create_before_destroy = true
}
}



13 changes: 13 additions & 0 deletions sg-alb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ resource "aws_security_group_rule" "https_from_world_to_alb" {
cidr_blocks = ["0.0.0.0/0"]
}

resource "aws_security_group_rule" "https_test_listener_from_world_to_alb" {
count = var.alb ? 1 : 0

description = "HTTPS ECS ALB Test Listener"
type = "ingress"
from_port = 8443
to_port = 8443
protocol = "tcp"
security_group_id = aws_security_group.alb[0].id
cidr_blocks = ["0.0.0.0/0"]
}


resource "aws_security_group_rule" "to_ecs_nodes" {
count = var.alb ? 1 : 0

Expand Down