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

feat: Deleting environments with globally deployed Aurora DB and improvements to EC2RouteTable, ElasticacheReplicationGroup and ElasticacheSubnetGroup properties #932

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/rebuy-de/aws-nuke/v2
go 1.19

require (
github.com/aws/aws-sdk-go v1.44.180
github.com/aws/aws-sdk-go v1.44.195
github.com/fatih/color v1.14.1
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
github.com/mb0/glob v0.0.0-20160210091149-1eb79d2de6c4
github.com/pkg/errors v0.9.1
github.com/rebuy-de/rebuy-go-sdk/v4 v4.2.0
github.com/rebuy-de/rebuy-go-sdk/v4 v4.3.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.8.1
Expand All @@ -31,4 +31,4 @@ require (
golang.org/x/sys v0.4.0 // indirect
golang.org/x/tools v0.5.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
)
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/aws/aws-sdk-go v1.44.180 h1:VLZuAHI9fa/3WME5JjpVjcPCNfpGHVMiHx8sLHWhMgI=
github.com/aws/aws-sdk-go v1.44.180/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go v1.44.195 h1:d5xFL0N83Fpsq2LFiHgtBUHknCRUPGHdOlCWt/jtOJs=
github.com/aws/aws-sdk-go v1.44.195/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -38,8 +38,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rebuy-de/rebuy-go-sdk/v4 v4.2.0 h1:4u6tb8zJFST2f4TM/QY09qKhVkv/eTBO/x3Xw6bbJUE=
github.com/rebuy-de/rebuy-go-sdk/v4 v4.2.0/go.mod h1:j9H3NYH4pcQcqfTUm2xKfEhFo8bMYwpwF9nVtCabkGU=
github.com/rebuy-de/rebuy-go-sdk/v4 v4.3.0 h1:iytQg040vkxN3TZy4ljgFS9FFvDHmh5nzuOTc1nq54U=
github.com/rebuy-de/rebuy-go-sdk/v4 v4.3.0/go.mod h1:NAhXHYuevxVCzx5MuCJ98jnXovZ86xZTikhjnw9Tjm0=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
Expand Down Expand Up @@ -118,4 +118,4 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 2 additions & 0 deletions resources/ec2-route-tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func (e *EC2RouteTable) Remove() error {

func (e *EC2RouteTable) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Identifier", e.routeTable.RouteTableId)

for _, tagValue := range e.routeTable.Tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}
Expand Down
22 changes: 22 additions & 0 deletions resources/elasticache-replicationgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/elasticache"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type ElasticacheReplicationGroup struct {
svc *elasticache.ElastiCache
groupID *string
tags []*elasticache.Tag
}

func init() {
Expand All @@ -28,9 +30,18 @@ func ListElasticacheReplicationGroups(sess *session.Session) ([]Resource, error)
}

for _, replicationGroup := range resp.ReplicationGroups {
tags, err := svc.ListTagsForResource(&elasticache.ListTagsForResourceInput{
ResourceName: replicationGroup.ARN,
})

if err != nil {
continue
}

resources = append(resources, &ElasticacheReplicationGroup{
svc: svc,
groupID: replicationGroup.ReplicationGroupId,
tags: tags.TagList,
})
}

Expand All @@ -57,6 +68,17 @@ func (i *ElasticacheReplicationGroup) Remove() error {
return nil
}

func (i *ElasticacheReplicationGroup) Properties() types.Properties {
properties := types.NewProperties().
Set("GroupID", i.groupID)

for _, tagValue := range i.tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}

return properties
}

func (i *ElasticacheReplicationGroup) String() string {
return *i.groupID
}
8 changes: 8 additions & 0 deletions resources/elasticache-subnetgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/elasticache"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type ElasticacheSubnetGroup struct {
Expand Down Expand Up @@ -48,6 +49,13 @@ func (i *ElasticacheSubnetGroup) Remove() error {
return nil
}

func (i *ElasticacheSubnetGroup) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", i.name)

return properties
}

func (i *ElasticacheSubnetGroup) String() string {
return *i.name
}
4 changes: 3 additions & 1 deletion resources/elb-elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ func (e *ELBLoadBalancer) Remove() error {

func (e *ELBLoadBalancer) Properties() types.Properties {
properties := types.NewProperties().
Set("CreatedTime", e.elb.CreatedTime.Format(time.RFC3339))
Set("CreatedTime", e.elb.CreatedTime.Format(time.RFC3339)).
Set("Name", e.elb.LoadBalancerName)

for _, tagValue := range e.tags {
properties.SetTag(tagValue.Key, tagValue.Value)
properties.SetTag(tagValue.Value, tagValue.Key)
}

return properties
Expand Down
4 changes: 3 additions & 1 deletion resources/elbv2-alb.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ func (e *ELBv2LoadBalancer) DisableProtection() error {

func (e *ELBv2LoadBalancer) Properties() types.Properties {
properties := types.NewProperties().
Set("CreatedTime", e.elb.CreatedTime.Format(time.RFC3339))
Set("CreatedTime", e.elb.CreatedTime.Format(time.RFC3339)).
Set("Name", e.elb.LoadBalancerName)

for _, tagValue := range e.tags {
properties.SetTag(tagValue.Key, tagValue.Value)
properties.SetTag(tagValue.Value, tagValue.Key)
}

return properties
Expand Down
74 changes: 74 additions & 0 deletions resources/rds-global-clusters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package resources

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

type RDSGlobalCluster struct {
svc *rds.RDS
id *string
deletionProtection bool
}

func init() {
register("RDSGlobalCluster", ListRDSGlobalClusters)
}

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

params := &rds.DescribeGlobalClustersInput{}
resp, err := svc.DescribeGlobalClusters(params)
if err != nil {
return nil, err
}

resources := make([]Resource, 0)
for _, instance := range resp.GlobalClusters {
resources = append(resources, &RDSGlobalCluster{
svc: svc,
id: instance.GlobalClusterIdentifier,
})
}

return resources, nil
}

func (i *RDSGlobalCluster) Remove() error {
if i.deletionProtection {
modifyParams := &rds.ModifyDBClusterInput{
DBClusterIdentifier: i.id,
DeletionProtection: aws.Bool(false),
}
_, err := i.svc.ModifyDBCluster(modifyParams)
if err != nil {
return err
}
}

params := &rds.DeleteGlobalClusterInput{
GlobalClusterIdentifier: i.id,
}

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

return nil
}

func (i *RDSGlobalCluster) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Identifier", i.id)
properties.Set("DeletionProtection", i.deletionProtection)

return properties
}

func (i *RDSGlobalCluster) String() string {
return aws.StringValue(i.id)
}
68 changes: 68 additions & 0 deletions resources/rds-secondary-cluster-attachments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package resources

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

type RDSSecondaryClusterAttachment struct {
svc *rds.RDS
GlobalClusterID *string
SecondaryClusterID *string
}

func init() {
register("RDSSecondaryClusterAttachment", ListRDSSecondaryClusterAttachment)
}

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

params := &rds.DescribeGlobalClustersInput{}
resp, err := svc.DescribeGlobalClusters(params)
if err != nil {
return nil, err
}

resources := make([]Resource, 0)
for _, instance := range resp.GlobalClusters {
for _, secondaryCluster := range instance.GlobalClusterMembers {

resources = append(resources, &RDSSecondaryClusterAttachment{
svc: svc,
GlobalClusterID: instance.GlobalClusterIdentifier,
SecondaryClusterID: secondaryCluster.DBClusterArn,
})
}
}

return resources, nil
}

func (i *RDSSecondaryClusterAttachment) Remove() error {
params := &rds.RemoveFromGlobalClusterInput{
DbClusterIdentifier: i.SecondaryClusterID,
GlobalClusterIdentifier: i.GlobalClusterID,
}

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

return nil
}

func (i *RDSSecondaryClusterAttachment) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("GlobalClusterID", i.GlobalClusterID)
properties.Set("SecondaryClusterID", i.SecondaryClusterID)

return properties
}

func (i *RDSSecondaryClusterAttachment) String() string {
return aws.StringValue(i.SecondaryClusterID)
}