Create code deployment pipeline with order

Hi, I am creating multiple code deployment pipelines on 1 AWS EC2. If have all of them be created the same time, all deployment except one will fail, because it can’t let multiple CD pipeline running the same time. Therefore, in my terraform script, I use dependent_services to create order.

module “a_cd” {

dependent_services = [
{service=module.the_ec2.main_service_name, instance_count=var.the_ec2.count}
]

}

module “b_cd” {

dependent_services = [
{service=module.the_ec2.main_sevice_name, instance_count=var.the_ec2.count},
{service=module.a_cd.service_name, instance_count = var.a_cd.count}
]

}

module “c_cd” {

dependent_services = [
{service=module.the_ec2.main_sevice_name, instance_count=var.the_ec2.count},
{service=module.a_cd.service_name, instance_count = var.a_cd.count},
{service=module.b_cd.service_name, instance_count = var.b_cd.count}
]

}

module “d_cd” {

dependent_services = [
{service=module.the_ec2.main_sevice_name, instance_count=var.the_ec2.count},
{service=module.a_cd.service_name, instance_count = var.a_cd.count},
{service=module.b_cd.service_name, instance_count = var.b_cd.count},
{service=module.c_cd.service_name, instance_count = var.c_cd.count}
]

}

module “e_cd” {

dependent_services = [
{service=module.the_ec2.main_sevice_name, instance_count=var.the_ec2.count},
{service=module.a_cd.service_name, instance_count = var.a_cd.count},
{service=module.b_cd.service_name, instance_count = var.b_cd.count},
{service=module.c_cd.service_name, instance_count = var.c_cd.count},
{service=module.c_cd.service_name, instance_count = var.d_cd.count}
]

}
So if some of the services are not turned on, their count will be 0, another script which check the successfully deployment of the dependent services on S3 will determine when to trigger the deployment. However, this method works when any 3 or less number of the services are on, but not working when there are 4 and more services are on. It fails to create even the EC2 in such a case without terminating the process. Any idea from terraform experts?