I already have an AWS auto scaling group, it has many EC2 instances, I want to include all instances in the auto scaling group behind a load balancer using terraform, I've tried to used terraform data to get EC2 instance with specific tags, but it fails as terraform data should return only one AWS object
1 Answers
1
votes
You really should NOT be managing routing to auto-scaled EC2s yourself. You should attach the scaling group to load balancer and let AWS worry about managing routing to individual EC2 as they scale up and down. Proper use of healthchecks will prevent you routing to unhealthy instances in the ASG.
You can create this type of relationship in terraform using:
- aws_autoscaling_attachment or
- Inline when creating an ASG in terraform, using target_group_arns
aws_instance
data source. Why are you trying to get information on all the instances in an ASG? – ydaetskcoR