From 8b0c1d889a39f9fc42b93732aff889bc5c16f8d8 Mon Sep 17 00:00:00 2001 From: hv202x1 <65007683+hv202x1@users.noreply.github.com> Date: Fri, 4 Mar 2022 10:38:31 +0100 Subject: [PATCH] fix(EC2NetworkInterface): fix panic on not attached NetworkInterfaces :bug: (#752) It is possible, that an interface is not attached. This leads to the fact that no AttachmendId is available. Accordingly, the string can also not be accessed. --- resources/ec2-network-interfaces.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/resources/ec2-network-interfaces.go b/resources/ec2-network-interfaces.go index 26eb9e99..d7a54e69 100644 --- a/resources/ec2-network-interfaces.go +++ b/resources/ec2-network-interfaces.go @@ -47,10 +47,13 @@ func (e *EC2NetworkInterface) Remove() error { Force: aws.Bool(true), }) if err != nil { - expected := fmt.Sprintf("The interface attachment '%s' does not exist.", *e.eni.Attachment.AttachmentId) - if !strings.Contains(err.Error(), expected) { - return err + if e.eni.Attachment.AttachmentId != nil { + expected := fmt.Sprintf("The interface attachment '%s' does not exist.", *e.eni.Attachment.AttachmentId) + if !strings.Contains(err.Error(), expected) { + return err + } } + } }