We have created a terraform template that creates an ECS cluster with a lot of elements - task definitions, ECR repos, services, VPC and associated elements, etc. The main input for this template is a list of services. Based on their names, task definitions, services, and ECR repos.
All the services are configured the same, except for one - let’s call it the “api1” service. This service has to be registered with a load balancer. The load balancer registration can only be done upon service creation and is configured as a resource inline configuration block (described here)
If I place a load_balancer block with conditionals, e.g. based on this service name, the creation of the rest of the services fails as they expect this block to be populated with data. I cannot use the “count” mechanism as this is not a resource.
I tied using dynamic configuration blocks, but it does not work for me as well.
A possible solution could be to loop over a module that creates the services and applies some logic to create/not create the load_balancer block, but module looping is not possible in terraform so far.
Any suggestions would be appreciated.