Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #255 from rebuy-de/nuke-eni
Browse files Browse the repository at this point in the history
nuke EC2 NetworkInterfaces
  • Loading branch information
svenwltr authored Aug 30, 2018
2 parents beced98 + 1a04386 commit 85f2913
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions resources/ec2-network-interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/rebuy-de/aws-nuke/pkg/types"
)

type EC2NetworkInterface struct {
svc *ec2.EC2
eni *ec2.NetworkInterface
}

func init() {
register("EC2NetworkInterface", ListEC2NetworkInterfaces)
}

func ListEC2NetworkInterfaces(sess *session.Session) ([]Resource, error) {
svc := ec2.New(sess)

resp, err := svc.DescribeNetworkInterfaces(nil)
if err != nil {
return nil, err
}

resources := make([]Resource, 0)
for _, out := range resp.NetworkInterfaces {

resources = append(resources, &EC2NetworkInterface{
svc: svc,
eni: out,
})
}

return resources, nil
}

func (e *EC2NetworkInterface) Remove() error {
params := &ec2.DeleteNetworkInterfaceInput{
NetworkInterfaceId: e.eni.NetworkInterfaceId,
}

_, err := e.svc.DeleteNetworkInterface(params)
if err != nil {
return err
}

return nil
}

func (r *EC2NetworkInterface) Properties() types.Properties {
return types.NewProperties().
Set("ID", r.eni.NetworkInterfaceId).
Set("VPC", r.eni.VpcId).
Set("AvailabilityZone", r.eni.AvailabilityZone).
Set("PrivateIPAddress", r.eni.PrivateIpAddress).
Set("SubnetID", r.eni.SubnetId).
Set("Status", r.eni.Status)
}

0 comments on commit 85f2913

Please sign in to comment.