@@ -149,6 +149,34 @@ resource "aws_lb_target_group" "this" {
149149 create_before_destroy = true
150150 }
151151
152+ }
153+
154+ resource "aws_lb_target_group" "green" {
155+ count = local. is_create_target_group && var. is_enable_blue_green_deployment ? 1 : 0
156+
157+ name = format (" %s-gn-tg" , substr (local. container_target_group_object . name , 0 , min (32 , length (local. container_target_group_object . name ))))
158+
159+ port = lookup (local. container_target_group_object , " port_mappings" , null )[0 ]. container_port
160+ protocol = lookup (local. container_target_group_object , " port_mappings" , null )[0 ]. container_port == 443 ? " HTTPS" : " HTTP"
161+ vpc_id = var. vpc_id
162+ target_type = " ip"
163+ deregistration_delay = var. target_group_deregistration_delay
164+
165+ health_check {
166+ interval = lookup (var. health_check , " interval" , null )
167+ path = lookup (var. health_check , " path" , null )
168+ timeout = lookup (var. health_check , " timeout" , null )
169+ healthy_threshold = lookup (var. health_check , " healthy_threshold" , null )
170+ unhealthy_threshold = lookup (var. health_check , " unhealthy_threshold" , null )
171+ matcher = lookup (var. health_check , " matcher" , null )
172+ }
173+
174+ tags = merge (local. tags , { " Name" = format (" %s-tg" , substr (local. container_target_group_object . name , 0 , min (29 , length (local. container_target_group_object . name )))) })
175+
176+ lifecycle {
177+ create_before_destroy = true
178+ }
179+
152180}
153181/* ------------------------------ Listener Rule ----------------------------- */
154182resource "aws_lb_listener_rule" "this" {
@@ -189,6 +217,57 @@ resource "aws_lb_listener_rule" "this" {
189217
190218 tags = local. tags
191219}
220+
221+ /* ------------------------------ Green Listener Rule ----------------------------- */
222+ resource "aws_lb_listener_rule" "green" {
223+ count = local. is_create_target_group && var. is_enable_blue_green_deployment ? 1 : 0
224+
225+ listener_arn = var. alb_listener_arn
226+ priority = var. alb_priority_green
227+
228+ action {
229+ type = " forward"
230+ target_group_arn = aws_lb_target_group. green [0 ]. arn
231+ }
232+
233+ condition {
234+ path_pattern {
235+ values = var. alb_paths == [] ? [" *" ] : var. alb_paths
236+ }
237+ }
238+
239+ dynamic "condition" {
240+ for_each = var. alb_host_header == null ? [] : [true ]
241+ content {
242+ host_header {
243+ values = [var . alb_host_header ]
244+ }
245+ }
246+ }
247+
248+ dynamic "condition" {
249+ for_each = var. custom_header_token == " " ? [] : [true ]
250+ content {
251+ http_header {
252+ http_header_name = " custom-header-token" # Match value within cloudfront module
253+ values = [var . custom_header_token ]
254+ }
255+ }
256+ }
257+
258+ dynamic "condition" {
259+ for_each = var. green_header_value == null ? [] : [true ]
260+ content {
261+ http_header {
262+ http_header_name = " green-header-name"
263+ values = [var . green_header_value ]
264+ }
265+ }
266+ }
267+
268+ tags = local. tags
269+ }
270+
192271/* -------------------------------------------------------------------------- */
193272/* Secret */
194273/* -------------------------------------------------------------------------- */
0 commit comments