Repository: aws-cloudformation/cfn-lint

Issue:
Used Parameter reported as unused
*cfn-lint version: 0.7.3*

Not sure if AWS::Serverless is supported but if it is then this template produces an incorrect warning:
```yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Parameters:
  Version:
    Type: String

Globals:
  Function:
    CodeUri:
      Bucket: "somebucket"
      Key: !Sub "lambda/code/lambda-${Version}-shaded.jar"

Resources:
  SomeLambda:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: com.SomeLambda::handleRequest
      Runtime: java8
      MemorySize: 256
```
Output from cfn-lint:
```
W2001 Parameter Version not used.
bug.yaml:4:3
```


Discussion:
thanks.  Looking into this one.  We do process the transform before doing any rule checking.  Since globals gets removed it looks like we lose the variable usage.  

I should be able to come up with some fix for this but thinking through the best way to do it.

Resolving patch:
diff --git a/src/cfnlint/__init__.py b/src/cfnlint/__init__.py
--- a/src/cfnlint/__init__.py
+++ b/src/cfnlint/__init__.py
@@ -373,6 +373,7 @@ def __init__(self, filename, template, regions=['us-east-1']):
             'Outputs',
             'Rules'
         ]
+        self.transform_globals = {}
 
     def __deepcopy__(self, memo):
         cls = self.__class__
@@ -601,7 +602,11 @@ def search_deep_keys(self, searchText):
             Search for keys in all parts of the templates
         """
         LOGGER.debug('Search for key %s as far down as the template goes', searchText)
-        return (self._search_deep_keys(searchText, self.template, []))
+        results = []
+        results.extend(self._search_deep_keys(searchText, self.template, []))
+        # Globals are removed during a transform.  They need to be checked manually
+        results.extend(self._search_deep_keys(searchText, self.transform_globals, []))
+        return results
 
     def get_condition_values(self, template, path=[]):
         """Evaluates conditions and brings back the values"""
@@ -873,6 +878,8 @@ def transform(self):
         # useless execution of the transformation.
         # Currently locked in to SAM specific
         if transform_type == 'AWS::Serverless-2016-10-31':
+            # Save the Globals section so its available for rule processing
+            self.cfn.transform_globals = self.cfn.template.get('Globals', {})
             transform = Transform(self.filename, self.cfn.template, self.cfn.regions[0])
             matches = transform.transform_template()
             self.cfn.template = transform.template()


Test patch:
diff --git a/test/fixtures/templates/good/parameters/used_transforms.yaml b/test/fixtures/templates/good/parameters/used_transforms.yaml
new file mode 100644
--- /dev/null
+++ b/test/fixtures/templates/good/parameters/used_transforms.yaml
@@ -0,0 +1,19 @@
+AWSTemplateFormatVersion: '2010-09-09'
+Transform: 'AWS::Serverless-2016-10-31'
+Parameters:
+  Version:
+    Type: String
+
+Globals:
+  Function:
+    CodeUri:
+      Bucket: "somebucket"
+      Key: !Sub "lambda/code/lambda-${Version}-shaded.jar"
+
+Resources:
+  SomeLambda:
+    Type: 'AWS::Serverless::Function'
+    Properties:
+      Handler: com.SomeLambda::handleRequest
+      Runtime: java8
+      MemorySize: 256
diff --git a/test/rules/parameters/test_used.py b/test/rules/parameters/test_used.py
--- a/test/rules/parameters/test_used.py
+++ b/test/rules/parameters/test_used.py
@@ -24,6 +24,9 @@ def setUp(self):
         """Setup"""
         super(TestParameterUsed, self).setUp()
         self.collection.register(Used())
+        self.success_templates = [
+            'fixtures/templates/good/parameters/used_transforms.yaml'
+        ]
 
     def test_file_positive(self):
         """Test Positive"""