[AWS] Get the IP adresses of a VPC endpoint using terraform

Hi,

In my AWS project i want to have a list of the IP adresses of a VPC endpoint using terraform.

Terraform provides a data_source to get the Network interfaces of the endpoint :

data "aws_vpc_endpoint" "my_endpoint" {
  vpc_id       = my_vpc
  service_name = "my_service"
}

data.aws_vpc_endpoint.my_endpoint.network_interface_ids

and it provides also a data source to get the IP of an ENI :

data "aws_network_interface" "bar" { 
  id = "eni-01234567" 
}
data.aws_network_interface.bar.private_ip

The network_interface_ids datasource will return in my case 2 ENI because i’m deploying in 2 AZ.

Now what i want is to have the data_source of the ENI (where i get the IP) to be dynamic. I want it to loop over the ENI.

Any way to do that ?

1 Like