func()

in pkg/aws/ec2/api/helper.go [572:614]


func (h *ec2APIHelper) GetBranchNetworkInterface(trunkID, subnetID *string) ([]*ec2types.NetworkInterface, error) {
	filters := []ec2types.Filter{
		{
			Name:   aws.String("tag:" + config.TrunkENIIDTag),
			Values: []string{*trunkID},
		},
		{
			Name:   aws.String("subnet-id"),
			Values: []string{*subnetID},
		},
	}

	describeNetworkInterfacesInput := &ec2.DescribeNetworkInterfacesInput{Filters: filters}
	var nwInterfaces []*ec2types.NetworkInterface
	for {
		describeNetworkInterfaceOutput, err := h.ec2Wrapper.DescribeNetworkInterfaces(describeNetworkInterfacesInput)
		if err != nil {
			return nil, err
		}

		if describeNetworkInterfaceOutput == nil || describeNetworkInterfaceOutput.NetworkInterfaces == nil ||
			len(describeNetworkInterfaceOutput.NetworkInterfaces) == 0 {
			// No more interface associated with the trunk, return the result
			break
		}

		// One or more interface associated with the trunk, return the result
		for _, nwInterface := range describeNetworkInterfaceOutput.NetworkInterfaces {
			// Only attach the required details to avoid consuming extra memory
			nwInterfaces = append(nwInterfaces, &ec2types.NetworkInterface{
				NetworkInterfaceId: nwInterface.NetworkInterfaceId,
				TagSet:             nwInterface.TagSet,
			})
		}

		if describeNetworkInterfaceOutput.NextToken == nil {
			break
		}

		describeNetworkInterfacesInput.NextToken = describeNetworkInterfaceOutput.NextToken
	}
	return nwInterfaces, nil
}