title: Is it possible to make a Codedeploy BlueGreen deployment to ECS use healthcheck data?
body: <p>I haven't been able to do this. I have healthchecks configured on my NLB's two target groups and they report healthy, but the deployment will take place and succeed even if the target group that is being switched to never becomes healthy.</p>
  
  <p>I can use alarms and lambda based tests to rollback of course, but I'm not sure if I can create an alarm that targets the currently non-serving-prod target group and not the currently serving-prod one in order to rollback the deployment properly.</p>
  
  <p>It seems that it's not possible to use anything but CodeDeployDefault.ECSAllAtOnce for an ECS green/blue, and I also see that its not possible at all to define minimum healthy hosts in ECS deployment configurations, so does this mean that CodeDeploy doesn't consider health status at all when deploying ECS?</p>
  
  <p>Here's my codedeploy terraform:</p>
  
  <pre><code>resource "aws_codedeploy_deployment_group" "deployment_group" {
    app_name               = aws_codedeploy_app.application.name
    deployment_group_name  = "${var.project_name}-deployment-group"
    service_role_arn       = aws_iam_role.codedeploy_role.arn
    deployment_config_name = "CodeDeployDefault.ECSAllAtOnce"
  
    # Automatically rollback on failure, alarm, or request.
    # See: https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_AutoRollbackConfiguration.html
    auto_rollback_configuration {
      enabled = "true"
      events = ["DEPLOYMENT_FAILURE", "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST"]
    }
  
    blue_green_deployment_config {
      # See: https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_DeploymentReadyOption.html
      deployment_ready_option {
        action_on_timeout = "CONTINUE_DEPLOYMENT"
      }
  
      terminate_blue_instances_on_deployment_success {
        action = "TERMINATE"
  
        # How many minutes to wait before terminating old instances
        termination_wait_time_in_minutes = 1
      }
    }
  
    # These settings are required for ECS deployments.
    deployment_style {
      deployment_option = "WITH_TRAFFIC_CONTROL"
      deployment_type   = "BLUE_GREEN"
    }
  
    # What to deploy
    ecs_service {
      cluster_name = aws_ecs_cluster.cluster.name
      service_name = aws_ecs_service.service.name
    }
  
    load_balancer_info {
      target_group_pair_info {
        # The path used by a load balancer to route production traffic when an Amazon ECS deployment is complete.
        prod_traffic_route {
          listener_arns = [aws_lb_listener.listener.arn]
        }
  
        # Blue group is the original group at first.
        target_group {
          name = aws_lb_target_group.blue_group.name
        }
  
        # Green group is the one that gets switched to at first.
        target_group {
          name = aws_lb_target_group.green_group.name
        }
      }
    }
  }
  
  </code></pre>
  
  <p>And here is my target groups:</p>
  
  <pre><code>resource "aws_lb_target_group" "blue_group" {
    name        = "${var.project_name}-${var.stage}-b"
    port        = 8080
    protocol    = "TCP"
    target_type = "ip"
    vpc_id = var.vpc_id
  
    health_check {
        path = var.nlb_healthcheck_path
        port = var.container_port
        protocol = "HTTP"
        healthy_threshold = 2
        unhealthy_threshold = 2
        interval = 10
     }
  
    stickiness {
        enabled = false
        type = "lb_cookie"
    }
  }
  
  resource "aws_lb_target_group" "green_group" {
    name        = "${var.project_name}-${var.stage}-g"
    port        = 8080
    protocol    = "TCP"
    target_type = "ip"
    vpc_id = var.vpc_id
  
    health_check {
        path = aws_lb_target_group.blue_group.health_check[0].path
        port = aws_lb_target_group.blue_group.health_check[0].port
        protocol = aws_lb_target_group.blue_group.health_check[0].protocol
        healthy_threshold = aws_lb_target_group.blue_group.health_check[0].healthy_threshold
        unhealthy_threshold = aws_lb_target_group.blue_group.health_check[0].unhealthy_threshold
        interval = aws_lb_target_group.blue_group.health_check[0].interval
     }
  
    stickiness {
        enabled = false
        type = "lb_cookie"
    }
  }
  </code></pre>