I want to find a solution to deploy one service called service2 only if the service service service3 is started and healthy. I use terraform to manage my infrastructure and deploy my different tasks.
What I tried to do is to add depends_on condition to my service:
resource "aws_ecs_service" "service2" {
name = "service2"
cluster = module.ecs_cluster_id
task_definition = aws_ecs_task_definition.service2.arn
desired_count = 1
launch_type = "FARGATE"
deployment_minimum_healthy_percent = 100
deployment_maximum_percent = 200
force_new_deployment = true
depends_on = [aws_ecs_service.service3]
propagate_tags = "SERVICE"
I also added for_new_deployment to force to deploy again even if there is no changes. When I deploy my service2, it seems wait until service3 stops deploying, but I have no guarantee that my service 3 is healthy and I'm not sure that the depends_on is the solution of my problem.
Do you have some recommendations?
You need to add
wait_for_steady_state = trueto yourservice3ECS service definition. Then Terraform will wait forservice3to be fully deployed and healthy before it proceeds with the rest of the deployment.