diff --git a/go.mod b/go.mod index e0e795a7b..ebf41d33f 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 -) +) \ No newline at end of file diff --git a/go.sum b/go.sum index f3731bbeb..48c813a39 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= \ No newline at end of file diff --git a/resources/ec2-route-tables.go b/resources/ec2-route-tables.go index e8313c360..1a9f4acca 100644 --- a/resources/ec2-route-tables.go +++ b/resources/ec2-route-tables.go @@ -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) } diff --git a/resources/elasticache-replicationgroups.go b/resources/elasticache-replicationgroups.go index b677263e4..05acb7b03 100644 --- a/resources/elasticache-replicationgroups.go +++ b/resources/elasticache-replicationgroups.go @@ -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() { @@ -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, }) } @@ -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 } diff --git a/resources/elasticache-subnetgroups.go b/resources/elasticache-subnetgroups.go index 2e17689e1..07af7f6b0 100644 --- a/resources/elasticache-subnetgroups.go +++ b/resources/elasticache-subnetgroups.go @@ -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 { @@ -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 } diff --git a/resources/elb-elb.go b/resources/elb-elb.go index fd37b0cf2..f43279782 100644 --- a/resources/elb-elb.go +++ b/resources/elb-elb.go @@ -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 diff --git a/resources/elbv2-alb.go b/resources/elbv2-alb.go index 12ea22b7e..64babad6c 100644 --- a/resources/elbv2-alb.go +++ b/resources/elbv2-alb.go @@ -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 diff --git a/resources/rds-global-clusters.go b/resources/rds-global-clusters.go new file mode 100644 index 000000000..9ebadc2b0 --- /dev/null +++ b/resources/rds-global-clusters.go @@ -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) +} diff --git a/resources/rds-secondary-cluster-attachments.go b/resources/rds-secondary-cluster-attachments.go new file mode 100644 index 000000000..dbf3dfe62 --- /dev/null +++ b/resources/rds-secondary-cluster-attachments.go @@ -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) +}