asked on
How can I reference list of ec2 instance names & IPs in datasorces.tf
My datasorces.tf list of ec2 instance names & IPs is throwing an error. Can someone advise on my error?
$ cat modules/ec2/datasources.tf
data "template_file" "configure" {
count = var.instance_count
template = file("${path.module}/files/configure.sh")
vars = {
instance_name = aws_instance.instance[count.index].tags.Name
all_names = aws_instance.instance[*].tags.Name
all_ips = aws_instance.instance[*].private_ip
}
}
Validation is fine but plan throws the following error:
│ Error: Incorrect attribute value type
│
│ on modules\ec2\datasources.tf line 5, in data "template_file" "configure":
│ 5: vars = {
│ 6: instance_name = aws_instance.instance[count.index].tags.Name
│ 7: all_names = aws_instance.instance[*].tags.Name
│ 8: all_ips = aws_instance.instance[*].private_ip
│ 9: }
│ ├────────────────
│ │ aws_instance.instance is tuple with 2 elements
│ │ count.index is 1
│
│ Inappropriate value for attribute "vars": element "all_names": string
│ required.