Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions resources/ec2-eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ 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 EC2Address struct {
svc *ec2.EC2
eip *ec2.Address
id string
ip string
}
Expand All @@ -28,6 +30,7 @@ func ListEC2Addresses(sess *session.Session) ([]Resource, error) {
for _, out := range resp.Addresses {
resources = append(resources, &EC2Address{
svc: svc,
eip: out,
id: *out.AllocationId,
ip: *out.PublicIp,
})
Expand All @@ -47,6 +50,15 @@ func (e *EC2Address) Remove() error {
return nil
}

func (e *EC2Address) Properties() types.Properties {
properties := types.NewProperties()
for _, tagValue := range e.eip.Tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}
properties.Set("AllocationId", e.id)
return properties
}

func (e *EC2Address) String() string {
return e.ip
}
12 changes: 9 additions & 3 deletions resources/ec2-security-groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

type EC2SecurityGroup struct {
svc *ec2.EC2
group *ec2.SecurityGroup
id *string
name *string
ingress []*ec2.IpPermission
Expand All @@ -33,6 +34,7 @@ func ListEC2SecurityGroups(sess *session.Session) ([]Resource, error) {
for _, group := range resp.SecurityGroups {
resources = append(resources, &EC2SecurityGroup{
svc: svc,
group: group,
id: group.GroupId,
name: group.GroupName,
ingress: group.IpPermissions,
Expand All @@ -55,7 +57,7 @@ func (sg *EC2SecurityGroup) Remove() error {
if len(sg.egress) > 0 {
egressParams := &ec2.RevokeSecurityGroupEgressInput{
GroupId: sg.id,
IpPermissions: sg.egress,
IpPermissions: sg.egress,
}

_, _ = sg.svc.RevokeSecurityGroupEgress(egressParams)
Expand Down Expand Up @@ -83,8 +85,12 @@ func (sg *EC2SecurityGroup) Remove() error {
}

func (sg *EC2SecurityGroup) Properties() types.Properties {
return types.NewProperties().
Set("Name", sg.name)
properties := types.NewProperties()
for _, tagValue := range sg.group.Tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}
properties.Set("Name", sg.name)
return properties
}

func (sg *EC2SecurityGroup) String() string {
Expand Down
23 changes: 21 additions & 2 deletions resources/iam-roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (

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

type IAMRole struct {
svc *iam.IAM
role *iam.Role
name string
path string
}
Expand All @@ -30,10 +32,18 @@ func ListIAMRoles(sess *session.Session) ([]Resource, error) {
}

for _, out := range resp.Roles {
getroleParams := &iam.GetRoleInput{
RoleName: out.RoleName,
}
getroleOutput, err := svc.GetRole(getroleParams)
if err != nil {
return nil, err
}
resources = append(resources, &IAMRole{
svc: svc,
name: *out.RoleName,
path: *out.Path,
role: getroleOutput.Role,
name: *getroleOutput.Role.RoleName,
path: *getroleOutput.Role.Path,
})
}

Expand Down Expand Up @@ -65,6 +75,15 @@ func (e *IAMRole) Remove() error {
return nil
}

func (role *IAMRole) Properties() types.Properties {
properties := types.NewProperties()
for _, tagValue := range role.role.Tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}
properties.Set("Name", role.name)
return properties
}

func (e *IAMRole) String() string {
return e.name
}