@@ -4,13 +4,17 @@ import (
4
4
"github.com/aws/aws-sdk-go/aws"
5
5
"github.com/aws/aws-sdk-go/aws/session"
6
6
"github.com/aws/aws-sdk-go/service/dynamodb"
7
+ "github.com/rebuy-de/aws-nuke/v2/pkg/config"
7
8
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
8
9
)
9
10
10
11
type DynamoDBTable struct {
11
- svc * dynamodb.DynamoDB
12
- id string
13
- tags []* dynamodb.Tag
12
+ svc * dynamodb.DynamoDB
13
+ id string
14
+ deletionProtection bool
15
+ tags []* dynamodb.Tag
16
+
17
+ featureFlags config.FeatureFlags
14
18
}
15
19
16
20
func init () {
@@ -27,23 +31,35 @@ func ListDynamoDBTables(sess *session.Session) ([]Resource, error) {
27
31
28
32
resources := make ([]Resource , 0 )
29
33
for _ , tableName := range resp .TableNames {
30
- tags , err := GetTableTags (svc , tableName )
34
+ table , tags , err := GetDynamoDBTable (svc , tableName )
31
35
32
36
if err != nil {
33
37
continue
34
38
}
35
39
36
40
resources = append (resources , & DynamoDBTable {
37
- svc : svc ,
38
- id : * tableName ,
39
- tags : tags ,
41
+ svc : svc ,
42
+ id : * tableName ,
43
+ deletionProtection : * table .DeletionProtectionEnabled ,
44
+ tags : tags ,
40
45
})
41
46
}
42
47
43
48
return resources , nil
44
49
}
45
50
46
51
func (i * DynamoDBTable ) Remove () error {
52
+ if i .deletionProtection && i .featureFlags .DisableDeletionProtection .DynamoDBTable {
53
+ modifyParams := & dynamodb.UpdateTableInput {
54
+ TableName : aws .String (i .id ),
55
+ DeletionProtectionEnabled : aws .Bool (false ),
56
+ }
57
+ _ , err := i .svc .UpdateTable (modifyParams )
58
+ if err != nil {
59
+ return err
60
+ }
61
+ }
62
+
47
63
params := & dynamodb.DeleteTableInput {
48
64
TableName : aws .String (i .id ),
49
65
}
@@ -56,29 +72,30 @@ func (i *DynamoDBTable) Remove() error {
56
72
return nil
57
73
}
58
74
59
- func GetTableTags (svc * dynamodb.DynamoDB , tableName * string ) ([]* dynamodb.Tag , error ) {
75
+ func GetDynamoDBTable (svc * dynamodb.DynamoDB , tableName * string ) (* dynamodb. TableDescription , []* dynamodb.Tag , error ) {
60
76
result , err := svc .DescribeTable (& dynamodb.DescribeTableInput {
61
77
TableName : aws .String (* tableName ),
62
78
})
63
79
64
80
if err != nil {
65
- return make ([]* dynamodb.Tag , 0 ), err
81
+ return nil , make ([]* dynamodb.Tag , 0 ), err
66
82
}
67
83
68
84
tags , err := svc .ListTagsOfResource (& dynamodb.ListTagsOfResourceInput {
69
85
ResourceArn : result .Table .TableArn ,
70
86
})
71
87
72
88
if err != nil {
73
- return make ([]* dynamodb.Tag , 0 ), err
89
+ return nil , make ([]* dynamodb.Tag , 0 ), err
74
90
}
75
91
76
- return tags .Tags , nil
92
+ return result . Table , tags .Tags , nil
77
93
}
78
94
79
95
func (i * DynamoDBTable ) Properties () types.Properties {
80
96
properties := types .NewProperties ()
81
97
properties .Set ("Identifier" , i .id )
98
+ properties .Set ("Deletion Protection" , i .deletionProtection )
82
99
83
100
for _ , tag := range i .tags {
84
101
properties .SetTag (tag .Key , tag .Value )
0 commit comments