Skip to content

Commit

Permalink
Add String() and handle expected errors from the detach (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
sas-pemcne committed Jan 3, 2022
1 parent 435d768 commit fc5ade6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion resources/ec2-network-interfaces.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package resources

import (
"fmt"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
Expand Down Expand Up @@ -37,13 +40,17 @@ func ListEC2NetworkInterfaces(sess *session.Session) ([]Resource, error) {
}

func (e *EC2NetworkInterface) Remove() error {

if e.eni.Attachment != nil {
_, err := e.svc.DetachNetworkInterface(&ec2.DetachNetworkInterfaceInput{
AttachmentId: e.eni.Attachment.AttachmentId,
Force: aws.Bool(true),
})
if err != nil {
return err
expected := fmt.Sprintf("The interface attachment '%s' does not exist.", *e.eni.Attachment.AttachmentId)
if !strings.Contains(err.Error(), expected) {
return err
}
}
}

Expand Down Expand Up @@ -73,3 +80,7 @@ func (r *EC2NetworkInterface) Properties() types.Properties {
Set("Status", r.eni.Status)
return properties
}

func (r *EC2NetworkInterface) String() string {
return *r.eni.NetworkInterfaceId
}

0 comments on commit fc5ade6

Please sign in to comment.