Terraform v0.12.9
Data source:
data "aws_vpc_endpoint_service" "transfer" {
service = "transfer.server"
}
resource "aws_vpc_endpoint" "transfer" {
vpc_id = "vpc-1111a11"
service_name = data.aws_vpc_endpoint_service.transfer.service_name
vpc_endpoint_type = "Interface"
security_group_ids = ["sg-ad1dbed6"]
subnet_ids = ["subnet-11c11111"]
private_dns_enabled = true
}
data "aws_network_interface" "transfer_eni" {
id = aws_vpc_endpoint.transfer.network_interface_ids[0]
}
https://gist.github.com/zswanson/9b95e843603648c01c6ba7813efd3bbc
The value of aws_vpc_endpoint.transfer.network_interface_ids should return a ilst, which can be indexed into as aws_vpc_endpoint.transfer.network_interface_ids[0]
terraform validate and terraform plan reports that the data from aws_vpc_endpoint.transfer.network_interface_idscannot be indexed.
Error: Invalid index
on main.tf line 41, in data "aws_network_interface" "transfer_eni":
41: id = aws_vpc_endpoint.transfer.network_interface_ids[0]
This value does not have any indices.
However, if I output the full object we can clearly see that it is, in fact, a list.
transfer_endpoint_eni = [
"eni-0184dcf948e89aef5",
]
We've been able to work around it in the following hacky manner but this is pretty ugly.
data "aws_network_interface" "transfer_eni" {
for_each = aws_vpc_endpoint.transfer.network_interface_ids
id = each.value
}
output “transfer_endpoint_eni_ip” {
value = data.aws_network_interface.transfer_eni[keys(data.aws_network_interface.transfer_eni)[0]].private_ip
}
Use a similar .tf to the sample code provided above
terraform validateUpdate - ok so we finally figured out that the return type of aws_vpc_endpoint.transfer.network_interface_ids is a set, so we can actually simplify but just casting it to a list. But, this is very counter-intuitive and difficult to work with, and its not documented.
Important Factoids
Update - ok so we finally figured out that the return type of aws_vpc_endpoint.transfer.network_interface_ids is a
set, so we can actually simplify but just casting it to a list. But, this is very counter-intuitive and difficult to work with, and its not documented.
Actually, it's documented that this shouldn't be necessary ;)
Explicit type conversions are rarely necessary in Terraform because it will convert types automatically where required. Use the explicit type conversion functions only to normalize types returned in module outputs.
From: https://www.terraform.io/docs/configuration/functions/tolist.html
I have the same problem with data.aws_vpc_endpoint.example.security_group_ids[0]. Is this similar enough or should I make a new issue for it?
Why was this closed? This is still an issue.
Why was this closed? This is still an issue.
this issue is still open - it was mentioned in a different issue, which is now closed though.
Lol, I totally misread that.
Most helpful comment
Actually, it's documented that this shouldn't be necessary ;)
From: https://www.terraform.io/docs/configuration/functions/tolist.html