File tree Expand file tree Collapse file tree 3 files changed +71
-2
lines changed Expand file tree Collapse file tree 3 files changed +71
-2
lines changed Original file line number Diff line number Diff 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+
5761output "ecs_nodes_secgrp_id" {
5862 value = aws_security_group. ecs_nodes . id
5963}
Original file line number Diff line number Diff 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+
63104resource "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
72117resource "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+
Original file line number Diff line number Diff 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+
3750resource "aws_security_group_rule" "to_ecs_nodes" {
3851 count = var. alb ? 1 : 0
3952
You can’t perform that action at this time.
0 commit comments