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
2 changes: 1 addition & 1 deletion terraform/app/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ module "web_service" {
vpc_id = aws_vpc.application_vpc.id
}
loadbalancer = {
target_group_arn = aws_lb_target_group.green.arn
target_group_arn = local.ecs_initial_lb_target_group
container_port = 4000
}
cluster_id = aws_ecs_cluster.cluster.id
Expand Down
1 change: 1 addition & 0 deletions terraform/app/env/preview.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ http_hosts = {

minimum_replicas = 3
appspec_bucket = "nhse-mavis-appspec-bucket-preview"
ecs_initial_lb_target_group = "green"
2 changes: 1 addition & 1 deletion terraform/app/loadbalancer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ resource "aws_lb_listener_rule" "forward_to_app" {
priority = 50000
action {
type = "forward"
target_group_arn = aws_lb_target_group.blue.arn
target_group_arn = local.ecs_initial_lb_target_group
}
condition {
path_pattern {
Expand Down
13 changes: 12 additions & 1 deletion terraform/app/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@ variable "maximum_replicas" {
description = "Maximum amount of allowed replicas"
}

variable "active_lb_target_group" {
type = string
description = "The actual loadbalancer target group is set by Codedeploy. However in scenarios where new resources behind the load balancer are created, terraform already needs to know the current target group. In this case, set the variable to the currently active target group."
default = "blue"
validation {
condition = contains(["blue", "green"], var.active_lb_target_group)
error_message = "Valid target groups: blue, green"
}
}

locals {
ecs_sg_ids = [module.web_service.security_group_id, module.good_job_service.security_group_id]
ecs_initial_lb_target_group = var.active_lb_target_group == "green" ? aws_lb_target_group.green.arn : aws_lb_target_group.blue.arn
ecs_sg_ids = [module.web_service.security_group_id, module.good_job_service.security_group_id]
}
Loading