I’m trying to create dynamically create a list of instance ids, to assign it to the loadbalancer. Based in this [question][1] I found I can do it using data "aws_instances"
Unfortunately I’m getting this error
Error: Your query returned no results. Please change your search criteria and try again.
This is the way I create my EC2 resources
resource "aws_instance" "one" {
instance_type = "${var.lc_instance_type}"
ami = "${var.dev_ami}"
count = "${var.instance_count}"
tags = {
Name = "${var.name_prefix}-id
}
}
And this is the way I’m using the data aws_instance and how I plant to use it in the EB resource
data "aws_instances" "read-ec2" {
instance_tags= {
Name = "${var.name_prefix}-id"
}
}
resource "aws_elb" "loadbalancer" {
instances = ["${data.aws_instances.read-ec2.ids}"]
listener {
...
}
}
Not sure if I’m using properly the instance_tags
option.