This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from rebuy-de/nuke-eni
nuke EC2 NetworkInterfaces
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |