Skip to content

Commit a6ec7c0

Browse files
elliot-dnxadenot
andauthored
adding test listener for blue/green deployment to be used on Codedeploy (#14)
* adding test listener for blue/green deployment to be used on Codedeploy * changing variable test_traffic_route_listener_arn name * Incorrect substring trimming first char * SG description Co-authored-by: Allan Denot <[email protected]>
1 parent f685f8e commit a6ec7c0

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

_outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ output "alb_listener_https_arn" {
5454
value = aws_lb_listener.ecs_https.*.arn
5555
}
5656

57+
output "test_traffic_route_listener_arn" {
58+
value = aws_lb_listener.ecs_test_https.*.arn
59+
}
60+
5761
output "ecs_nodes_secgrp_id" {
5862
value = aws_security_group.ecs_nodes.id
5963
}

alb.tf

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,72 @@ resource "aws_lb_listener" "ecs_http_redirect" {
6060
}
6161
}
6262

63+
resource "aws_lb_listener" "ecs_test_https" {
64+
count = var.alb ? 1 : 0
65+
66+
load_balancer_arn = aws_lb.ecs[0].arn
67+
port = "8443"
68+
protocol = "HTTPS"
69+
ssl_policy = "ELBSecurityPolicy-2016-08"
70+
certificate_arn = var.certificate_arn
71+
72+
default_action {
73+
type = "forward"
74+
#target_group_arn = aws_lb_target_group.ecs_replacement_https[0].arn
75+
target_group_arn = aws_lb_target_group.ecs_default_https[0].arn
76+
}
77+
}
78+
79+
resource "aws_lb_listener" "ecs_test_http_redirect" {
80+
count = var.alb ? 1 : 0
81+
82+
load_balancer_arn = aws_lb.ecs[0].arn
83+
port = "8080"
84+
protocol = "HTTP"
85+
86+
default_action {
87+
type = "redirect"
88+
89+
redirect {
90+
port = "8443"
91+
protocol = "HTTPS"
92+
status_code = "HTTP_301"
93+
}
94+
}
95+
}
96+
97+
# Generate a random string to add it to the name of the Target Group
98+
resource "random_string" "alb_prefix" {
99+
length = 4
100+
upper = false
101+
special = false
102+
}
103+
63104
resource "aws_lb_target_group" "ecs_default_http" {
64105
count = var.alb ? 1 : 0
65106

66-
name = "ecs-${var.name}-default-http"
107+
name = substr("ecs-${var.name}-default-http-${random_string.alb_prefix.result}", 0, 32)
67108
port = 80
68109
protocol = "HTTP"
69110
vpc_id = var.vpc_id
111+
112+
lifecycle {
113+
create_before_destroy = true
114+
}
70115
}
71116

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

75-
name = "ecs-${var.name}-default-https"
120+
name = substr("ecs-${var.name}-default-https-${random_string.alb_prefix.result}", 0, 32)
76121
port = 80
77122
protocol = "HTTP"
78123
vpc_id = var.vpc_id
124+
125+
lifecycle {
126+
create_before_destroy = true
127+
}
79128
}
129+
130+
131+

sg-alb.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ resource "aws_security_group_rule" "https_from_world_to_alb" {
3434
cidr_blocks = ["0.0.0.0/0"]
3535
}
3636

37+
resource "aws_security_group_rule" "https_test_listener_from_world_to_alb" {
38+
count = var.alb ? 1 : 0
39+
40+
description = "HTTPS ECS ALB Test Listener"
41+
type = "ingress"
42+
from_port = 8443
43+
to_port = 8443
44+
protocol = "tcp"
45+
security_group_id = aws_security_group.alb[0].id
46+
cidr_blocks = ["0.0.0.0/0"]
47+
}
48+
49+
3750
resource "aws_security_group_rule" "to_ecs_nodes" {
3851
count = var.alb ? 1 : 0
3952

0 commit comments

Comments
 (0)