func detachVolumes(client *ec2.EC2, attachParams []storage.VolumeAttachmentParams) ([]error, error) { results := make([]error, len(attachParams)) for i, params := range attachParams { _, err := client.DetachVolume(params.VolumeId, string(params.InstanceId), "", false) // Process aws specific error information. if err != nil { if ec2Err, ok := err.(*ec2.Error); ok { switch ec2Err.Code { // attachment not found means this volume is already detached. case attachmentNotFound: err = nil } } } if err != nil { results[i] = errors.Annotatef( err, "detaching %v from %v", params.Volume, params.Machine, ) } } return results, nil }