diff --git a/resources/ec2-network-interfaces.go b/resources/ec2-network-interfaces.go index 5b5db9aa..26eb9e99 100644 --- a/resources/ec2-network-interfaces.go +++ b/resources/ec2-network-interfaces.go @@ -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" @@ -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 + } } } @@ -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 +} diff --git a/resources/ec2-snapshots.go b/resources/ec2-snapshots.go index 0baa81a7..1ab96331 100644 --- a/resources/ec2-snapshots.go +++ b/resources/ec2-snapshots.go @@ -2,6 +2,8 @@ package resources import ( "fmt" + "time" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" @@ -9,9 +11,10 @@ import ( ) type EC2Snapshot struct { - svc *ec2.EC2 - id string - tags []*ec2.Tag + svc *ec2.EC2 + id string + startTime *time.Time + tags []*ec2.Tag } func init() { @@ -33,9 +36,10 @@ func ListEC2Snapshots(sess *session.Session) ([]Resource, error) { resources := make([]Resource, 0) for _, out := range resp.Snapshots { resources = append(resources, &EC2Snapshot{ - svc: svc, - id: *out.SnapshotId, - tags: out.Tags, + svc: svc, + id: *out.SnapshotId, + startTime: out.StartTime, + tags: out.Tags, }) } @@ -44,6 +48,8 @@ func ListEC2Snapshots(sess *session.Session) ([]Resource, error) { func (e *EC2Snapshot) Properties() types.Properties { properties := types.NewProperties() + properties.Set("StartTime", e.startTime.Format(time.RFC3339)) + for _, tagValue := range e.tags { properties.Set(fmt.Sprintf("tag:%v", *tagValue.Key), tagValue.Value) } diff --git a/resources/iam-policies.go b/resources/iam-policies.go index 4a550fdb..6213a051 100644 --- a/resources/iam-policies.go +++ b/resources/iam-policies.go @@ -45,7 +45,7 @@ func ListIAMPolicies(sess *session.Session) ([]Resource, error) { policy, err := GetIAMPolicy(svc, listedPolicy.Arn) if err != nil { logrus.Errorf("Failed to get listed policy %s: %v", *listedPolicy.PolicyName, err) - break + continue } policies = append(policies, policy) }