prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Nested stack reference to InstanceProfile triggers E2502 Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile
  *cfn-lint version: `0.8.1`*
  
  # Description of issue
  
  When using nested stacks and passing IamInstanceProfile ARNs between stacks, E2502 is triggered though it shouldn't be.
  
  # Steps to reproduce
  
  Create a parent template like this
  ```yaml
  AWSTemplateFormatVersion: 2010-09-09
  Resources:
    IAMInstanceProfile:
      Type: AWS::CloudFormation::Stack
      Properties:
        TemplateURL: https://s3-us-west-2.amazonaws.com/example-bucket/example-instance-profile.yml
    Instance:
      Type: AWS::CloudFormation::Stack
      Properties:
        Parameters:
          IamInstanceProfile: !GetAtt IAMInstanceProfile.Outputs.InstanceProfileArn
        TemplateURL: https://s3-us-west-2.amazonaws.com/example-bucket/example-instance.yml
  ```
  and a child template like this
  
  ```yaml
  AWSTemplateFormatVersion: 2010-09-09
  Resources:
    InstanceProfile:
      Type: AWS::IAM::InstanceProfile
      Properties:
        Roles:
          - ExampleRole
  Outputs:
    InstanceProfileArn:
      Value: !GetAtt InstanceProfile.Arn
  ```
  
  # Expected results
  
  The `IamInstanceProfile` parameter in the parent template's `Instance` sub-stack resource definition does indeed contain a valid IAM Instance Profile ARN (passed in from the `IAMInstanceProfile` sub-stack resource and as a result, there should be no error.
  
  Ideally cfn-lint would recognize that `GetAtt` is referencing an output from another stack which very well could be an InstanceProfile ARN and as a result, optimistically not report this error.
  
  Alternatively, if cfn-lint could introspect the sub-stack and determine the object type of the output, it would know whether or not it was the correct object type.
  
  # Actual results
  
  cfn-lint reports the error
  
  > E2502 Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for Resources/Instance/Properties/Parameters/IamInstanceProfile/Fn::GetAtt
  > example-parent.yml:11:9
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/cfnlint/rules/resources/iam/InstanceProfile.py`
  Content:
  ```
  1 """
  2   Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3 
  4   Permission is hereby granted, free of charge, to any person obtaining a copy of this
  5   software and associated documentation files (the "Software"), to deal in the Software
  6   without restriction, including without limitation the rights to use, copy, modify,
  7   merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  8   permit persons to whom the Software is furnished to do so.
  9 
  10   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  11   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  12   PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  13   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  14   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  15   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16 """
  17 from cfnlint import CloudFormationLintRule
  18 from cfnlint import RuleMatch
  19 
  20 
  21 class InstanceProfile(CloudFormationLintRule):
  22     """Check if IamInstanceProfile are used"""
  23     id = 'E2502'
  24     shortdesc = 'Check if IamInstanceProfile are using the name and not ARN'
  25     description = 'See if there are any properties IamInstanceProfile' + \
  26                   'are using name and not ARN'
  27     source_url = 'https://github.com/awslabs/cfn-python-lint'
  28     tags = ['properties']
  29 
  30     def match(self, cfn):
  31         """Check CloudFormation IamInstanceProfile Parameters"""
  32 
  33         matches = []
  34 
  35         # Build the list of keys
  36         trees = cfn.search_deep_keys('Fn::GetAtt')
  37         # Filter only resources
  38         # Disable pylint for Pylint 2
  39         # pylint: disable=W0110
  40         trees = filter(lambda x: x[0] == 'Resources', trees)
  41         for tree in trees:
  42             if any(e == 'IamInstanceProfile' for e in tree):
  43                 obj = tree[-1]
  44                 objtype = cfn.template.get('Resources', {}).get(obj[0], {}).get('Type')
  45                 if objtype:
  46                     if objtype != 'AWS::IAM::InstanceProfile':
  47                         message = 'Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for %s' % (
  48                             '/'.join(map(str, tree[:-1])))
  49                         matches.append(RuleMatch(tree[:-1], message))
  50                     else:
  51                         if cfn.template.get('Resources', {}).get(tree[1], {}).get('Type') in ['AWS::EC2::SpotFleet']:
  52                             if obj[1] != 'Arn':
  53                                 message = 'Property IamInstanceProfile should be an ARN for %s' % (
  54                                     '/'.join(map(str, tree[:-1])))
  55                                 matches.append(RuleMatch(tree[:-1], message))
  56                         else:
  57                             if obj[1] == 'Arn':
  58                                 message = 'Property IamInstanceProfile shouldn\'t be an ARN for %s' % (
  59                                     '/'.join(map(str, tree[:-1])))
  60                                 matches.append(RuleMatch(tree[:-1], message))
  61 
  62         # Search Refs
  63         trees = cfn.search_deep_keys('Ref')
  64         # Filter only resoureces
  65         trees = filter(lambda x: x[0] == 'Resources', trees)
  66         for tree in trees:
  67             if any(e == 'IamInstanceProfile' for e in tree):
  68                 obj = tree[-1]
  69                 objtype = cfn.template.get('Resources', {}).get(obj, {}).get('Type')
  70                 if objtype:
  71                     if objtype != 'AWS::IAM::InstanceProfile':
  72                         message = 'Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for %s' % (
  73                             '/'.join(map(str, tree[:-1])))
  74                         matches.append(RuleMatch(tree[:-1], message))
  75 
  76         return matches
  77
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/src/cfnlint/rules/resources/iam/InstanceProfile.py b/src/cfnlint/rules/resources/iam/InstanceProfile.py
  --- a/src/cfnlint/rules/resources/iam/InstanceProfile.py
  +++ b/src/cfnlint/rules/resources/iam/InstanceProfile.py
  @@ -43,12 +43,17 @@
                   obj = tree[-1]
                   objtype = cfn.template.get('Resources', {}).get(obj[0], {}).get('Type')
                   if objtype:
  -                    if objtype != 'AWS::IAM::InstanceProfile':
  +                    if objtype not in ['AWS::IAM::InstanceProfile', 'AWS::CloudFormation::Stack', 'AWS::CloudFormation::CustomResource']:
                           message = 'Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for %s' % (
                               '/'.join(map(str, tree[:-1])))
                           matches.append(RuleMatch(tree[:-1], message))
                       else:
  -                        if cfn.template.get('Resources', {}).get(tree[1], {}).get('Type') in ['AWS::EC2::SpotFleet']:
  +                        if objtype in ['AWS::CloudFormation::Stack']:
  +                            if obj[1] != 'Outputs':
  +                                message = 'Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for %s' % (
  +                                    '/'.join(map(str, tree[:-1])))
  +                                matches.append(RuleMatch(tree[:-1], message))
  +                        elif cfn.template.get('Resources', {}).get(tree[1], {}).get('Type') in ['AWS::EC2::SpotFleet']:
                               if obj[1] != 'Arn':
                                   message = 'Property IamInstanceProfile should be an ARN for %s' % (
                                       '/'.join(map(str, tree[:-1])))
  
verification_info: {"golden_diff": "diff --git a/src/cfnlint/rules/resources/iam/InstanceProfile.py b/src/cfnlint/rules/resources/iam/InstanceProfile.py\n--- a/src/cfnlint/rules/resources/iam/InstanceProfile.py\n+++ b/src/cfnlint/rules/resources/iam/InstanceProfile.py\n@@ -43,12 +43,17 @@\n                 obj = tree[-1]\n                 objtype = cfn.template.get('Resources', {}).get(obj[0], {}).get('Type')\n                 if objtype:\n-                    if objtype != 'AWS::IAM::InstanceProfile':\n+                    if objtype not in ['AWS::IAM::InstanceProfile', 'AWS::CloudFormation::Stack', 'AWS::CloudFormation::CustomResource']:\n                         message = 'Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for %s' % (\n                             '/'.join(map(str, tree[:-1])))\n                         matches.append(RuleMatch(tree[:-1], message))\n                     else:\n-                        if cfn.template.get('Resources', {}).get(tree[1], {}).get('Type') in ['AWS::EC2::SpotFleet']:\n+                        if objtype in ['AWS::CloudFormation::Stack']:\n+                            if obj[1] != 'Outputs':\n+                                message = 'Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for %s' % (\n+                                    '/'.join(map(str, tree[:-1])))\n+                                matches.append(RuleMatch(tree[:-1], message))\n+                        elif cfn.template.get('Resources', {}).get(tree[1], {}).get('Type') in ['AWS::EC2::SpotFleet']:\n                             if obj[1] != 'Arn':\n                                 message = 'Property IamInstanceProfile should be an ARN for %s' % (\n                                     '/'.join(map(str, tree[:-1])))\n", "issue": "Nested stack reference to InstanceProfile triggers E2502 Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile\n*cfn-lint version: `0.8.1`*\r\n\r\n# Description of issue\r\n\r\nWhen using nested stacks and passing IamInstanceProfile ARNs between stacks, E2502 is triggered though it shouldn't be.\r\n\r\n# Steps to reproduce\r\n\r\nCreate a parent template like this\r\n```yaml\r\nAWSTemplateFormatVersion: 2010-09-09\r\nResources:\r\n  IAMInstanceProfile:\r\n    Type: AWS::CloudFormation::Stack\r\n    Properties:\r\n      TemplateURL: https://s3-us-west-2.amazonaws.com/example-bucket/example-instance-profile.yml\r\n  Instance:\r\n    Type: AWS::CloudFormation::Stack\r\n    Properties:\r\n      Parameters:\r\n        IamInstanceProfile: !GetAtt IAMInstanceProfile.Outputs.InstanceProfileArn\r\n      TemplateURL: https://s3-us-west-2.amazonaws.com/example-bucket/example-instance.yml\r\n```\r\nand a child template like this\r\n\r\n```yaml\r\nAWSTemplateFormatVersion: 2010-09-09\r\nResources:\r\n  InstanceProfile:\r\n    Type: AWS::IAM::InstanceProfile\r\n    Properties:\r\n      Roles:\r\n        - ExampleRole\r\nOutputs:\r\n  InstanceProfileArn:\r\n    Value: !GetAtt InstanceProfile.Arn\r\n```\r\n\r\n# Expected results\r\n\r\nThe `IamInstanceProfile` parameter in the parent template's `Instance` sub-stack resource definition does indeed contain a valid IAM Instance Profile ARN (passed in from the `IAMInstanceProfile` sub-stack resource and as a result, there should be no error.\r\n\r\nIdeally cfn-lint would recognize that `GetAtt` is referencing an output from another stack which very well could be an InstanceProfile ARN and as a result, optimistically not report this error.\r\n\r\nAlternatively, if cfn-lint could introspect the sub-stack and determine the object type of the output, it would know whether or not it was the correct object type.\r\n\r\n# Actual results\r\n\r\ncfn-lint reports the error\r\n\r\n> E2502 Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for Resources/Instance/Properties/Parameters/IamInstanceProfile/Fn::GetAtt\r\n> example-parent.yml:11:9\n", "before_files": [{"content": "\"\"\"\n  Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this\n  software and associated documentation files (the \"Software\"), to deal in the Software\n  without restriction, including without limitation the rights to use, copy, modify,\n  merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n  permit persons to whom the Software is furnished to do so.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,\n  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\n  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\"\"\"\nfrom cfnlint import CloudFormationLintRule\nfrom cfnlint import RuleMatch\n\n\nclass InstanceProfile(CloudFormationLintRule):\n    \"\"\"Check if IamInstanceProfile are used\"\"\"\n    id = 'E2502'\n    shortdesc = 'Check if IamInstanceProfile are using the name and not ARN'\n    description = 'See if there are any properties IamInstanceProfile' + \\\n                  'are using name and not ARN'\n    source_url = 'https://github.com/awslabs/cfn-python-lint'\n    tags = ['properties']\n\n    def match(self, cfn):\n        \"\"\"Check CloudFormation IamInstanceProfile Parameters\"\"\"\n\n        matches = []\n\n        # Build the list of keys\n        trees = cfn.search_deep_keys('Fn::GetAtt')\n        # Filter only resources\n        # Disable pylint for Pylint 2\n        # pylint: disable=W0110\n        trees = filter(lambda x: x[0] == 'Resources', trees)\n        for tree in trees:\n            if any(e == 'IamInstanceProfile' for e in tree):\n                obj = tree[-1]\n                objtype = cfn.template.get('Resources', {}).get(obj[0], {}).get('Type')\n                if objtype:\n                    if objtype != 'AWS::IAM::InstanceProfile':\n                        message = 'Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for %s' % (\n                            '/'.join(map(str, tree[:-1])))\n                        matches.append(RuleMatch(tree[:-1], message))\n                    else:\n                        if cfn.template.get('Resources', {}).get(tree[1], {}).get('Type') in ['AWS::EC2::SpotFleet']:\n                            if obj[1] != 'Arn':\n                                message = 'Property IamInstanceProfile should be an ARN for %s' % (\n                                    '/'.join(map(str, tree[:-1])))\n                                matches.append(RuleMatch(tree[:-1], message))\n                        else:\n                            if obj[1] == 'Arn':\n                                message = 'Property IamInstanceProfile shouldn\\'t be an ARN for %s' % (\n                                    '/'.join(map(str, tree[:-1])))\n                                matches.append(RuleMatch(tree[:-1], message))\n\n        # Search Refs\n        trees = cfn.search_deep_keys('Ref')\n        # Filter only resoureces\n        trees = filter(lambda x: x[0] == 'Resources', trees)\n        for tree in trees:\n            if any(e == 'IamInstanceProfile' for e in tree):\n                obj = tree[-1]\n                objtype = cfn.template.get('Resources', {}).get(obj, {}).get('Type')\n                if objtype:\n                    if objtype != 'AWS::IAM::InstanceProfile':\n                        message = 'Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for %s' % (\n                            '/'.join(map(str, tree[:-1])))\n                        matches.append(RuleMatch(tree[:-1], message))\n\n        return matches\n", "path": "src/cfnlint/rules/resources/iam/InstanceProfile.py"}], "after_files": [{"content": "\"\"\"\n  Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this\n  software and associated documentation files (the \"Software\"), to deal in the Software\n  without restriction, including without limitation the rights to use, copy, modify,\n  merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n  permit persons to whom the Software is furnished to do so.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,\n  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\n  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\"\"\"\nfrom cfnlint import CloudFormationLintRule\nfrom cfnlint import RuleMatch\n\n\nclass InstanceProfile(CloudFormationLintRule):\n    \"\"\"Check if IamInstanceProfile are used\"\"\"\n    id = 'E2502'\n    shortdesc = 'Check if IamInstanceProfile are using the name and not ARN'\n    description = 'See if there are any properties IamInstanceProfile' + \\\n                  'are using name and not ARN'\n    source_url = 'https://github.com/awslabs/cfn-python-lint'\n    tags = ['properties']\n\n    def match(self, cfn):\n        \"\"\"Check CloudFormation IamInstanceProfile Parameters\"\"\"\n\n        matches = []\n\n        # Build the list of keys\n        trees = cfn.search_deep_keys('Fn::GetAtt')\n        # Filter only resources\n        # Disable pylint for Pylint 2\n        # pylint: disable=W0110\n        trees = filter(lambda x: x[0] == 'Resources', trees)\n        for tree in trees:\n            if any(e == 'IamInstanceProfile' for e in tree):\n                obj = tree[-1]\n                objtype = cfn.template.get('Resources', {}).get(obj[0], {}).get('Type')\n                if objtype:\n                    if objtype not in ['AWS::IAM::InstanceProfile', 'AWS::CloudFormation::Stack', 'AWS::CloudFormation::CustomResource']:\n                        message = 'Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for %s' % (\n                            '/'.join(map(str, tree[:-1])))\n                        matches.append(RuleMatch(tree[:-1], message))\n                    else:\n                        if objtype in ['AWS::CloudFormation::Stack']:\n                            if obj[1] != 'Outputs':\n                                message = 'Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for %s' % (\n                                    '/'.join(map(str, tree[:-1])))\n                                matches.append(RuleMatch(tree[:-1], message))\n                        elif cfn.template.get('Resources', {}).get(tree[1], {}).get('Type') in ['AWS::EC2::SpotFleet']:\n                            if obj[1] != 'Arn':\n                                message = 'Property IamInstanceProfile should be an ARN for %s' % (\n                                    '/'.join(map(str, tree[:-1])))\n                                matches.append(RuleMatch(tree[:-1], message))\n                        else:\n                            if obj[1] == 'Arn':\n                                message = 'Property IamInstanceProfile shouldn\\'t be an ARN for %s' % (\n                                    '/'.join(map(str, tree[:-1])))\n                                matches.append(RuleMatch(tree[:-1], message))\n\n        # Search Refs\n        trees = cfn.search_deep_keys('Ref')\n        # Filter only resoureces\n        trees = filter(lambda x: x[0] == 'Resources', trees)\n        for tree in trees:\n            if any(e == 'IamInstanceProfile' for e in tree):\n                obj = tree[-1]\n                objtype = cfn.template.get('Resources', {}).get(obj, {}).get('Type')\n                if objtype:\n                    if objtype != 'AWS::IAM::InstanceProfile':\n                        message = 'Property IamInstanceProfile should relate to AWS::IAM::InstanceProfile for %s' % (\n                            '/'.join(map(str, tree[:-1])))\n                        matches.append(RuleMatch(tree[:-1], message))\n\n        return matches\n", "path": "src/cfnlint/rules/resources/iam/InstanceProfile.py"}]}