There are a few different ways to proceed here. The main root thing is that you’ll need to decide what ought to happen to the downstream resources (those that depend on the task definition) when the task definition isn’t enabled.
I’m rusty on ECS but if I’m remembering correctly it doesn’t make sense to have an ECS service without a task definition, so probably in this case you’d want to apply a conditional count to the service resource too:
The above says that there should be the same number of ECS services as there are task definitions (by your current declaration of the task definition, either zero or one) and that each service should take its task definition from the corresponding instance of aws_ecs_task_definition.ldap.
In other situations the more appropriate thing to do would be to keep the downstream resource itself unconditional but to make one of its arguments literal. I don’t think that really make sense in the situation you’re describing, but I want to mention it for completeness in case you run into other situations like this later:
The above sets task_definition to null in the case where there are no task definitions, while keeping the ECS service resource. Setting a resource argument to null is the same as not setting it at all, so this would be appropriate only for an optional argument, and so I expect this would fail for task_definition which IIRC is a required argument of aws_ecs_service.
i have checked the issue, missing: missing the count after the resource with the arn.
thanks a lot, i have closed an important requirement ( use less modules as possible)
this is is my requirements, i would like write terraform code, most clean as possible.