I'm doing this...
resource "aws_instance" "web" {
count = "${length(split(",", lookup(var.subnet_ids, var.application)))}"
subnet_id = "${element(split(",", lookup(var.subnet_ids, var.application)), count.index)}"
...
}
which works swimmingly. I end up with aws_instance.web.0 and aws_instance.web.1 in the correct subnets, etc.
Now i'm trying to extend it and create an aws_ebs_volume called data for each ec2 instance. However, I'm having trouble figuring out how to get the aws_instance id's to correlate with the correct ec2 instance. I was trying to get this to work...
resource "aws_volume_attachment" "data" {
count = "${length(split(",", aws_instance.web.*.id))}"
device_name = "/dev/xvdb"
volume_id = "${element(aws_ebs_volume.data.*.id, count.index)}"
instance_id = "${element(aws_instance.web.*.id, count.index)}"
}
but I get this error...
* Error reading aws_instance.web count: strconv.ParseInt: parsing "${length(split(\",\", lookup(var.subnet_ids, var.application)))}": invalid syntax
Anyone have any good examples of this?
TIA