5
5
6
6
from typing import Any
7
7
8
+ import cfnlint .data .AdditionalSpecs
9
+ from cfnlint .helpers import load_resource
8
10
from cfnlint .jsonschema import Validator
9
11
from cfnlint .rules .jsonschema .CfnLintJsonSchema import CfnLintJsonSchema
10
12
11
13
12
14
class UpdateReplacePolicyDeletionPolicyOnStatefulResourceTypes (CfnLintJsonSchema ):
13
- """Check for UpdateReplacePolicy / DeletionPolicy"""
14
-
15
15
id = "I3011"
16
16
shortdesc = "Check stateful resources have a set UpdateReplacePolicy/DeletionPolicy"
17
17
description = (
@@ -28,36 +28,13 @@ def __init__(self):
28
28
all_matches = True ,
29
29
)
30
30
31
- self .config ["types" ] = [
32
- "AWS::Backup::BackupVault" ,
33
- "AWS::CloudFormation::Stack" ,
34
- "AWS::Cognito::UserPool" ,
35
- "AWS::DocDB::DBCluster" ,
36
- "AWS::DocDB::DBInstance" ,
37
- "AWS::DynamoDB::GlobalTable" ,
38
- "AWS::DynamoDB::Table" ,
39
- "AWS::EC2::Volume" ,
40
- "AWS::EFS::FileSystem" ,
41
- "AWS::EMR::Cluster" ,
42
- "AWS::ElastiCache::CacheCluster" ,
43
- "AWS::ElastiCache::ReplicationGroup" ,
44
- "AWS::Elasticsearch::Domain" ,
45
- "AWS::FSx::FileSystem" ,
46
- "AWS::KMS::Key" ,
47
- "AWS::Kinesis::Stream" ,
48
- "AWS::Logs::LogGroup" ,
49
- "AWS::Neptune::DBCluster" ,
50
- "AWS::Neptune::DBInstance" ,
51
- "AWS::OpenSearchService::Domain" ,
52
- "AWS::Organizations::Account" ,
53
- "AWS::QLDB::Ledger" ,
54
- "AWS::RDS::DBCluster" ,
55
- "AWS::RDS::DBInstance" ,
56
- "AWS::Redshift::Cluster" ,
57
- # "AWS::S3::Bucket", # can't be deleted without being empty
58
- "AWS::SDB::Domain" ,
59
- "AWS::SQS::Queue" ,
60
- "AWS::SecretsManager::Secret" ,
31
+ spec = load_resource (cfnlint .data .AdditionalSpecs , "StatefulResources.json" )
32
+ self .likely_stateful_resource_types = [
33
+ resource_type
34
+ for resource_type , descr in spec ["ResourceTypes" ].items ()
35
+ # Resources that won't be deleted if they're not empty (ex: S3)
36
+ # don't need to be checked for policies, as chance of mistakes are low.
37
+ if not descr .get ("DeleteRequiresEmptyResource" , False )
61
38
]
62
39
63
40
self ._schema = {"required" : ["DeletionPolicy" , "UpdateReplacePolicy" ]}
@@ -68,7 +45,7 @@ def validate(self, validator: Validator, s: Any, instance: Any, schema: Any):
68
45
if not isinstance (resource_type , str ):
69
46
return
70
47
71
- if resource_type not in self .config . get ( "types" ) : # type: ignore
48
+ if resource_type not in self .likely_stateful_resource_types : # type: ignore
72
49
return
73
50
74
51
for err in super ().validate (validator , s , instance , self ._schema ):
0 commit comments