Skip to content

Commit b4c8075

Browse files
author
lycbrian
committed
chore: support blue-green deployment
1 parent 66a34c1 commit b4c8075

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Change Log
22

3+
## [v1.4.0] - 2025-08-20
4+
5+
### Added
6+
7+
- Support blue-green deployment
8+
- var: is_enable_blue_green_deployment
9+
- resource: aws_lb_target_group.green
10+
311
## [v1.3.1] - 2025-04-09
12+
413
### Added
514

615
- lifecycle create_before_destroy for aws_lb_target_group

examples/terraform-test/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,8 @@ module "api_service" {
177177
}
178178
}
179179

180+
# Blue-Green Deployment
181+
is_enable_blue_green_deployment = true
182+
180183
tags = var.custom_tags
181184
}

main.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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-green-tg", substr(local.container_target_group_object.name, 0, min(29, 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 ----------------------------- */
154182
resource "aws_lb_listener_rule" "this" {

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,13 @@ variable "container" {
305305
type = any
306306
default = {}
307307
}
308+
309+
/* -------------------------------------------------------------------------- */
310+
/* Blue-Green Deployment */
311+
/* -------------------------------------------------------------------------- */
312+
variable "is_enable_blue_green_deployment" {
313+
description = "Whether the service enable blue-green deployment"
314+
type = bool
315+
default = false
316+
}
317+

0 commit comments

Comments
 (0)