Skip to content

Commit 9742aab

Browse files
authored
fix: detect and delete RDS clusters/instances with deletion protection enabled (#955)
Resolves issue where RDS clusters and instances with deletion protection enabled were not being detected during discovery, even when matching tag and time filters. Since the nukeAll functions already disable deletion protection before deletion, these resources can be safely included in discovery and will be properly cleaned up. Fixes #953
1 parent 6a693ea commit 9742aab

File tree

4 files changed

+7
-15
lines changed

4 files changed

+7
-15
lines changed

aws/resources/rds.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ func (di *DBInstances) getAll(ctx context.Context, configObj config.Config) ([]*
2222
var names []*string
2323

2424
for _, database := range result.DBInstances {
25-
// Skip deletion-protected instances when config doesn't explicitly include them
26-
if database.DeletionProtection != nil && *database.DeletionProtection && !configObj.DBInstances.IncludeDeletionProtected {
27-
continue
28-
}
29-
3025
if configObj.DBInstances.ShouldInclude(config.ResourceValue{
3126
Time: database.InstanceCreateTime,
3227
Name: database.DBInstanceIdentifier,

aws/resources/rds_cluster.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ func (instance *DBClusters) getAll(c context.Context, configObj config.Config) (
4747

4848
var names []*string
4949
for _, database := range result.DBClusters {
50-
// Skip deletion-protected clusters when config doesn't explicitly include them
51-
if database.DeletionProtection != nil && *database.DeletionProtection && !configObj.DBClusters.IncludeDeletionProtected {
52-
continue
53-
}
54-
5550
if configObj.DBClusters.ShouldInclude(config.ResourceValue{
5651
Name: database.DBClusterIdentifier,
5752
Time: database.ClusterCreateTime,

aws/resources/rds_cluster_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ func TestRDSClusterGetAll(t *testing.T) {
6363
},
6464
}
6565

66-
// Test Case 1: Empty config - should exclude deletion-protected clusters by default
66+
// Test Case 1: Empty config - should include both protected and unprotected clusters
67+
// Deletion protection is automatically disabled during deletion, so we include these clusters
6768
clusters, err := dbCluster.getAll(context.Background(), config.Config{DBClusters: config.AWSProtectectableResourceType{}})
6869
assert.NoError(t, err)
6970
assert.Contains(t, aws.ToStringSlice(clusters), strings.ToLower(testName))
70-
assert.NotContains(t, aws.ToStringSlice(clusters), strings.ToLower(testProtectedName))
71+
assert.Contains(t, aws.ToStringSlice(clusters), strings.ToLower(testProtectedName))
7172

72-
// Test Case 2: IncludeDeletionProtected=true - should include both protected and unprotected clusters
73+
// Test Case 2: With IncludeDeletionProtected flag - behavior is now the same as Test Case 1
74+
// since deletion-protected clusters are always included
7375
clusters, err = dbCluster.getAll(context.Background(), config.Config{
7476
DBClusters: config.AWSProtectectableResourceType{
7577
IncludeDeletionProtected: true,

aws/resources/rds_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestDBInstances_GetAll(t *testing.T) {
100100
}{
101101
"emptyFilter": {
102102
configObj: config.AWSProtectectableResourceType{},
103-
expected: []string{testIdentifier1, testIdentifier2},
103+
expected: []string{testIdentifier1, testIdentifier2, testIdentifier3},
104104
},
105105
"nameExclusionFilter": {
106106
configObj: config.AWSProtectectableResourceType{ResourceType: config.ResourceType{
@@ -110,7 +110,7 @@ func TestDBInstances_GetAll(t *testing.T) {
110110
}},
111111
},
112112
}},
113-
expected: []string{testIdentifier1, testIdentifier2},
113+
expected: []string{testIdentifier1, testIdentifier2, testIdentifier3},
114114
},
115115
"timeAfterExclusionFilter": {
116116
configObj: config.AWSProtectectableResourceType{

0 commit comments

Comments
 (0)