in pkg/aws/ec2/api/helper.go [304:345]
func (h *ec2APIHelper) CreateAndAttachNetworkInterface(instanceId *string, subnetId *string, securityGroups []string,
tags []*ec2.Tag, deviceIndex *int64, description *string, interfaceType *string, secondaryIPCount int) (*ec2.NetworkInterface, error) {
nwInterface, err := h.CreateNetworkInterface(description, subnetId, securityGroups, tags, secondaryIPCount, interfaceType)
if err != nil {
return nil, err
}
var attachmentId *string
attachmentId, err = h.AttachNetworkInterfaceToInstance(instanceId, nwInterface.NetworkInterfaceId, deviceIndex)
if err != nil {
errDelete := h.DeleteNetworkInterface(nwInterface.NetworkInterfaceId)
if errDelete != nil {
return nwInterface, fmt.Errorf("failed to attach the network interface %v: failed to delete the nw interfac %v",
err, errDelete)
}
return nil, err
}
err = h.SetDeleteOnTermination(attachmentId, nwInterface.NetworkInterfaceId)
if err != nil {
errDelete := h.DetachAndDeleteNetworkInterface(attachmentId, nwInterface.NetworkInterfaceId)
if errDelete != nil {
return nwInterface, fmt.Errorf("failed to set deletion on termination: %v: failed to delete nw interface: %v",
err, errDelete)
}
return nil, err
}
err = h.WaitForNetworkInterfaceStatusChange(nwInterface.NetworkInterfaceId, ec2.AttachmentStatusAttached)
if err != nil {
errDelete := h.DetachAndDeleteNetworkInterface(attachmentId, nwInterface.NetworkInterfaceId)
if errDelete != nil {
return nwInterface, fmt.Errorf("failed to verify status attached: %v: failed to delete nw interface: %v",
err, errDelete)
}
return nil, err
}
return nwInterface, nil
}