Skip to content

Commit 24e6f29

Browse files
mluk-awskddejong
andauthored
Supporting intrinsic function in DeletionPolicy and UpdateReplacePolicy (#2784)
Co-authored-by: Kevin DeJong <[email protected]>
1 parent 571464f commit 24e6f29

10 files changed

+47
-116
lines changed

src/cfnlint/rules/resources/DeletionPolicy.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DeletionPolicy(CloudFormationLintRule):
1515
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html"
1616
tags = ["resources", "deletionpolicy"]
1717

18-
def check_value(self, key, path, res_type, has_lang_exten_transform):
18+
def check_value(self, key, path, res_type):
1919
"""Check resource names for DeletionPolicy"""
2020
matches = []
2121

@@ -25,7 +25,7 @@ def check_value(self, key, path, res_type, has_lang_exten_transform):
2525

2626
supported_functions_joined = ", ".join(supported_functions)
2727

28-
if has_lang_exten_transform and isinstance(key, dict):
28+
if isinstance(key, dict):
2929
if len(key) == 1:
3030
for index_key, _ in key.items():
3131
if index_key not in supported_functions:
@@ -88,11 +88,6 @@ def match(self, cfn):
8888
RuleMatch(path, message.format("/".join(map(str, path))))
8989
)
9090
else:
91-
has_lang_exten_transform = cfn.has_language_extensions_transform()
92-
matches.extend(
93-
self.check_value(
94-
deletion_policies, path, res_type, has_lang_exten_transform
95-
)
96-
)
91+
matches.extend(self.check_value(deletion_policies, path, res_type))
9792

9893
return matches

src/cfnlint/rules/resources/UpdateReplacePolicy.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class UpdateReplacePolicy(CloudFormationLintRule):
1515
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatereplacepolicy.html"
1616
tags = ["resources", "updatereplacepolicy"]
1717

18-
def check_value(self, key, path, res_type, has_lang_exten_transform):
18+
def check_value(self, key, path, res_type):
1919
"""Check resource names for UpdateReplacePolicy"""
2020
matches = []
2121

@@ -25,7 +25,7 @@ def check_value(self, key, path, res_type, has_lang_exten_transform):
2525

2626
supported_functions_joined = ", ".join(supported_functions)
2727

28-
if has_lang_exten_transform and isinstance(key, dict):
28+
if isinstance(key, dict):
2929
if len(key) == 1:
3030
for index_key, _ in key.items():
3131
if index_key not in supported_functions:
@@ -87,14 +87,8 @@ def match(self, cfn):
8787
RuleMatch(path, message.format("/".join(map(str, path))))
8888
)
8989
else:
90-
has_lang_exten_transform = cfn.has_language_extensions_transform()
9190
matches.extend(
92-
self.check_value(
93-
updatereplace_policies,
94-
path,
95-
res_type,
96-
has_lang_exten_transform,
97-
)
91+
self.check_value(updatereplace_policies, path, res_type)
9892
)
9993

10094
return matches

test/fixtures/templates/bad/resources_deletionpolicy.yaml

+19-8
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,28 @@ Resources:
2121
DBInstanceClass: db.m1.small
2222
Engine: MySQL
2323
DeletionPolicy: CopyRegion
24-
RefPolicy:
25-
Type: AWS::RDS::DBInstance
26-
Properties:
27-
AllocatedStorage: '5'
28-
DBInstanceClass: db.m1.small
29-
Engine: MySQL
30-
DeletionPolicy: !Ref DBPolicy
3124
MyIAMUser:
3225
Type: AWS::IAM::User
3326
Properties:
3427
# Username field not supported for secure strings
3528
UserName: 'bob'
3629
DeletionPolicy: Snapshot
37-
30+
UnsupportedIntrinsic:
31+
Type: AWS::CloudFormation::WaitConditionHandle
32+
DeletionPolicy:
33+
Fn::Cidr:
34+
- "192.168.0.0/24"
35+
- 6
36+
- 5
37+
InvalidMapping:
38+
Type: AWS::RDS::DBInstance
39+
Properties:
40+
AllocatedStorage: '5'
41+
DBInstanceClass: db.m1.small
42+
Engine: MySQL
43+
DeletionPolicy:
44+
A: a1
45+
B:
46+
- b1
47+
- b2
48+
UpdateReplacePolicy: "Retain"

test/fixtures/templates/bad/resources_lang_extensions_updatereplacepolicy.yaml

-33
This file was deleted.

test/fixtures/templates/bad/resources_updatereplacepolicy.yaml

+18-8
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,27 @@ Resources:
2121
DBInstanceClass: db.m1.small
2222
Engine: MySQL
2323
UpdateReplacePolicy: CopyRegion
24-
RefPolicy:
25-
Type: AWS::RDS::DBInstance
26-
Properties:
27-
AllocatedStorage: '5'
28-
DBInstanceClass: db.m1.small
29-
Engine: MySQL
30-
UpdateReplacePolicy: !Ref DBPolicy
3124
MyIAMUser:
3225
Type: AWS::IAM::User
3326
Properties:
3427
# Username field not supported for secure strings
3528
UserName: 'bob'
3629
UpdateReplacePolicy: Snapshot
37-
30+
UnsupportedIntrinsic:
31+
Type: AWS::CloudFormation::WaitConditionHandle
32+
UpdateReplacePolicy:
33+
Fn::Cidr:
34+
- "192.168.0.0/24"
35+
- 6
36+
- 5
37+
InvalidMapping:
38+
Type: AWS::RDS::DBInstance
39+
Properties:
40+
AllocatedStorage: '5'
41+
DBInstanceClass: db.m1.small
42+
Engine: MySQL
43+
UpdateReplacePolicy:
44+
A: a1
45+
B:
46+
- b1
47+
- b2

test/fixtures/templates/bad/test_lang_extensions_deletionpolicy.yaml

-31
This file was deleted.

test/fixtures/templates/good/resources_lang_extensions_deletionpolicy.yaml renamed to test/fixtures/templates/good/resources_deletionpolicy.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
AWSTemplateFormatVersion: '2010-09-09'
2-
Transform: AWS::LanguageExtensions
32
Conditions:
43
IsUsEast1: !Equals [!Ref 'AWS::Region', 'us-east-1']
54
Parameters:

test/fixtures/templates/good/resources_lang_extensions_updatereplacepolicy.yaml renamed to test/fixtures/templates/good/resources_updatereplacepolicy.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
AWSTemplateFormatVersion: '2010-09-09'
2-
Transform: AWS::LanguageExtensions
32
Conditions:
43
IsUsEast1: !Equals [!Ref 'AWS::Region', 'us-east-1']
54
Parameters:

test/unit/rules/resources/test_deletionpolicy.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def setUp(self):
1717
super(TestResourceDeletionPolicy, self).setUp()
1818
self.collection.register(DeletionPolicy())
1919
self.success_templates = [
20-
"test/fixtures/templates/good/resources_lang_extensions_deletionpolicy.yaml"
20+
"test/fixtures/templates/good/resources_deletionpolicy.yaml"
2121
]
2222

2323
def test_file_positive(self):
@@ -27,11 +27,5 @@ def test_file_positive(self):
2727
def test_file_negative(self):
2828
"""Test failure"""
2929
self.helper_file_negative(
30-
"test/fixtures/templates/bad/resources_deletionpolicy.yaml", 4
31-
)
32-
33-
def test_lang_extensions_file_negative(self):
34-
"""Test failure"""
35-
self.helper_file_negative(
36-
"test/fixtures/templates/bad/test_lang_extensions_deletionpolicy.yaml", 3
30+
"test/fixtures/templates/bad/resources_deletionpolicy.yaml", 5
3731
)

test/unit/rules/resources/test_updatereplacepolicy.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def setUp(self):
1717
super(TestResourceUpdateReplacePolicy, self).setUp()
1818
self.collection.register(UpdateReplacePolicy())
1919
self.success_templates = [
20-
"test/fixtures/templates/good/resources_lang_extensions_updatereplacepolicy.yaml"
20+
"test/fixtures/templates/good/resources_updatereplacepolicy.yaml"
2121
]
2222

2323
def test_file_positive(self):
@@ -27,12 +27,5 @@ def test_file_positive(self):
2727
def test_file_negative(self):
2828
"""Test failure"""
2929
self.helper_file_negative(
30-
"test/fixtures/templates/bad/resources_updatereplacepolicy.yaml", 4
31-
)
32-
33-
def test_lang_extensions_file_negative(self):
34-
"""Test failure"""
35-
self.helper_file_negative(
36-
"test/fixtures/templates/bad/resources_lang_extensions_updatereplacepolicy.yaml",
37-
3,
30+
"test/fixtures/templates/bad/resources_updatereplacepolicy.yaml", 5
3831
)

0 commit comments

Comments
 (0)