From 2e46050f09533de764f8612d47a87876d82cb6bc Mon Sep 17 00:00:00 2001 From: Luis Capelo <953118+luiscape@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:31:46 +0100 Subject: [PATCH] Ignore public IPs when collecting metadata (#7) Instances may have public IPs assigned after they are provisioned. The `vprox` server will fail to start if public IPs aren't yet assigned to the instance. This seems unnecessary because it doesn't need to know the public IP of the instance at all as far as I understand. This change makes it easier to start vprox servers in ec2 instances with multiple ENIs but no public IPs, and then assign public IPs later. (AWS doesn't let you automatically assign public IPs if an instance is launched with multiple ENIs so there's a period in which we have no public IPs.) --- lib/aws.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/lib/aws.go b/lib/aws.go index e7fa909..3d28b21 100644 --- a/lib/aws.go +++ b/lib/aws.go @@ -13,7 +13,6 @@ import ( type AwsInterface struct { MacAddress string InterfaceId string // eni-[XXXXXXXXXX] - PublicIps []string PrivateIps []string } @@ -47,25 +46,15 @@ func (am *AwsMetadata) GetAddresses() ([]AwsInterface, error) { return nil, err } - result, err := am.get(fmt.Sprintf("%s/%s/ipv4-associations", prefix, mac)) + result, err := am.get(fmt.Sprintf("%s/%s/local-ipv4s", prefix, mac)) if err != nil { - return nil, err - } - publicIps := strings.Split(result, "\n") - privateIps := make([]string, 0, len(publicIps)) - - for _, ip := range publicIps { - privateIp, err := am.get(fmt.Sprintf("%s/%s/ipv4-associations/%s", prefix, mac, ip)) - if err != nil { - return nil, err - } - privateIps = append(privateIps, privateIp) + return nil, fmt.Errorf("failed to get private IPs for MAC %s: %v", mac, err) } + privateIps := strings.Split(result, "\n") interfaces = append(interfaces, AwsInterface{ MacAddress: mac, InterfaceId: interfaceId, - PublicIps: publicIps, PrivateIps: privateIps, }) }