From 33983345c7eee06dd04e945ceac6112ae9cc5279 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Fri, 16 Feb 2024 08:48:02 -0800 Subject: [PATCH] Set Application location when its a string (#3060) * Ignore W3002 will be ignored when the template has the SAM transform --- .../resources/properties/PropertiesTemplated.py | 3 +++ src/cfnlint/template/template.py | 14 +++++++++++--- .../resources/properties/templated_code_sam.yaml | 6 ++++++ .../properties/test_properties_templated.py | 3 ++- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/templates/good/resources/properties/templated_code_sam.yaml diff --git a/src/cfnlint/rules/resources/properties/PropertiesTemplated.py b/src/cfnlint/rules/resources/properties/PropertiesTemplated.py index 23f70fc812..c79fb2c7ef 100644 --- a/src/cfnlint/rules/resources/properties/PropertiesTemplated.py +++ b/src/cfnlint/rules/resources/properties/PropertiesTemplated.py @@ -60,6 +60,9 @@ def match_resource_properties(self, properties, resourcetype, path, cfn): """Check CloudFormation Properties""" matches = [] + if cfn.has_serverless_transform(): + return [] + for key in self.templated_exceptions.get(resourcetype, []): matches.extend( cfn.check_value( diff --git a/src/cfnlint/template/template.py b/src/cfnlint/template/template.py index 0658f5d798..e06ab639be 100644 --- a/src/cfnlint/template/template.py +++ b/src/cfnlint/template/template.py @@ -94,9 +94,6 @@ def build_graph(self): def has_language_extensions_transform(self): """Check if the template has language extensions transform declared""" - LOGGER.debug( - "Check if the template has language extensions transform declaration" - ) lang_extensions_transform = "AWS::LanguageExtensions" transform_declaration = self.transform_pre["Transform"] transform_type = ( @@ -106,6 +103,17 @@ def has_language_extensions_transform(self): ) return bool(lang_extensions_transform in transform_type) + def has_serverless_transform(self): + """Check if the template has SAM transform declared""" + lang_extensions_transform = "AWS::Serverless-2016-10-31" + transform_declaration = self.transform_pre["Transform"] + transform_type = ( + transform_declaration + if isinstance(transform_declaration, list) + else [transform_declaration] + ) + return bool(lang_extensions_transform in transform_type) + def get_resources(self, resource_type=[]): """ Get Resources diff --git a/test/fixtures/templates/good/resources/properties/templated_code_sam.yaml b/test/fixtures/templates/good/resources/properties/templated_code_sam.yaml new file mode 100644 index 0000000000..dda15233c4 --- /dev/null +++ b/test/fixtures/templates/good/resources/properties/templated_code_sam.yaml @@ -0,0 +1,6 @@ +Transform: AWS::Serverless-2016-10-31 +Resources: + Function: + Type: AWS::Serverless::Application + Properties: + Location: path/ diff --git a/test/unit/rules/resources/properties/test_properties_templated.py b/test/unit/rules/resources/properties/test_properties_templated.py index 7543476a88..00f082028c 100644 --- a/test/unit/rules/resources/properties/test_properties_templated.py +++ b/test/unit/rules/resources/properties/test_properties_templated.py @@ -18,7 +18,8 @@ def setUp(self): super(TestPropertiesTemplated, self).setUp() self.collection.register(PropertiesTemplated()) self.success_templates = [ - "test/fixtures/templates/good/resources/properties/templated_code.yaml" + "test/fixtures/templates/good/resources/properties/templated_code.yaml", + "test/fixtures/templates/good/resources/properties/templated_code_sam.yaml", ] def test_file_positive(self):