1
votes

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
Some data sources allow returning a list (such as terraform.io/docs/providers/aws/d/subnet_ids.html vs terraform.io/docs/providers/aws/d/subnet.html) but not the aws_instance data source. Why are you trying to get information on all the instances in an ASG?ydaetskcoR

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.

See 1 2

You can create this type of relationship in terraform using: