Do you know if there is an easy way to retrieve a container's IP from its task definition? From what I see in AWS documentation, no attribute is returned for AWS::ECS::TaskDefinition resource type.
I need this IP to set it in my AWS::ElasticLoadBalancingV2::TargetGroup resource.
After some searches on google I could create an internal load balancer with an elastic IP, associate my container to it and then use the LB's IP. But I find it a bit overkill.
It doesn't return an IP because ECS can remove and recreate the task anytime there is a health check failure, any time you deploy a new container version, or any time an ECS auto-scaling threshold is met. Each time one of those events happens the IP of the ECS task(s) will change. CloudFormation won't be involved in those events, so you can't rely on CloudFormation to keep your target group updated.
The solution is to configure your task to run in an ECS service, and configure the ECS service to keep a load balancer's target group updated with the task IPs. In this scenario you don't set the target IPs directly in the target group, you simply inform ECS of the target group and it makes sure the target IPs are always in sync.
After some searches on google I could create an internal loadbalancer with an elastic IP, associate my container to it and then use the LB's IP. But I find it a bit overkill.
That wouldn't actually work at all. That would just push your problem from one load balancer's target group to another load balancer's target group. You would still need to associate the ECS task's IP with the internal load balancer's target group, and you'd be back to the same problem you have now.