Terraform-provider-aws: aws_vpc_endpoint attribute network_interface_ids is not indexable as a list despite being a list

Created on 27 Sep 2019  ·  5Comments  ·  Source: hashicorp/terraform-provider-aws

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.12.9

  • provider.aws v2.29.0

Affected Resource(s)

Data source:

  • aws_vpc_endpoint

Terraform Configuration Files

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]
}

Debug Output

https://gist.github.com/zswanson/9b95e843603648c01c6ba7813efd3bbc

Panic Output

Expected Behavior

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]

Actual Behavior

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
}

Steps to Reproduce


Use a similar .tf to the sample code provided above

  1. terraform validate

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.

References

documentation good first issue servicec2

Most helpful comment

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

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings