Example #1
0
 def test_is_resource_available(self):
     """ Test is resource available """
     temp_obj = cfnlint.helpers.convert_dict({
         'Mappings': {'location': {'us-east-1': {'primary': 'True'}}},
         'Conditions': {
             'isPrimary': {'Fn::Equals': ['True', {'Fn::FindInMap': ['location', {'Ref': 'AWS::Region'}, 'primary']}]},
         },
         'Resources': {
             'LambdaExecutionRole': {
                 'Condition': 'isPrimary',
                 'Type': 'AWS::IAM::Role',
                 'Properties': {}
             },
             'AMIIDLookup': {
                 'Type': 'AWS::Lambda::Function',
                 'Properties': {
                     'Handler': 'index.handler',
                     'Role': {
                         'Fn::If': ['isPrimary', {'Fn::GetAtt': 'LambdaExecutionRole.Arn'}, {'Ref': 'AWS::NoValue'}]
                     }
                 }
             }
         },
         'Outputs': {
             'lambdaArn': {
                 'Condition': 'isPrimary',
                 'Value': {'Fn::GetAtt': 'LambdaExecutionRole.Arn'}
             }
         }
     })
     template = Template('test.yaml', temp_obj)
     # Doesn't fail with a Fn::If based condition
     self.assertEqual(
         template.is_resource_available(
             ['Resources', 'AMIIDLookup', 'Properties', 'Role', 'Fn::If',
                 1, 'Fn::GetAtt', ['LambdaExecutionRole', 'Arn']],
             'LambdaExecutionRole'
         ),
         []
     )
     # Doesn't fail when the Output has a Condition defined
     self.assertEqual(
         template.is_resource_available(
             ['Outputs', 'lambdaArn', 'Value', 'Fn::GetAtt', ['LambdaExecutionRole', 'Arn']],
             'LambdaExecutionRole'
         ),
         []
     )
     # Doesn't fail when the Resource doesn't exist
     self.assertEqual(
         template.is_resource_available(
             ['Outputs', 'lambdaArn', 'Value', 'Fn::GetAtt', ['LambdaExecutionRole', 'Arn']],
             'UnknownResource'
         ),
         []
     )
Example #2
0
 def test_is_resource_not_available(self):
     """ Test is resource available """
     temp_obj = cfnlint.helpers.convert_dict({
         'Mappings': {'location': {'us-east-1': {'primary': 'True'}}},
         'Conditions': {
             'isPrimary': {'Fn::Equals': ['True', {'Fn::FindInMap': ['location', {'Ref': 'AWS::Region'}, 'primary']}]},
         },
         'Resources': {
             'LambdaExecutionRole': {
                 'Condition': 'isPrimary',
                 'Type': 'AWS::IAM::Role',
                 'Properties': {}
             },
             'AMIIDLookup': {
                 'Type': 'AWS::Lambda::Function',
                 'Properties': {
                     'Handler': 'index.handler',
                     'Role': {'Fn::GetAtt': 'LambdaExecutionRole.Arn'}
                 }
             }
         },
         'Outputs': {
             'lambdaArn': {
                 'Value': {'Fn::GetAtt': 'LambdaExecutionRole.Arn'}
             }
         }
     })
     template = Template('test.yaml', temp_obj)
     self.assertEqual(
         template.is_resource_available(
             ['Resources', 'AMIIDLookup', 'Properties', 'Role', 'Fn::If',
                 1, 'Fn::GetAtt', ['LambdaExecutionRole', 'Arn']],
             'LambdaExecutionRole'
         ),
         [{'isPrimary': False}]
     )
     self.assertEqual(
         template.is_resource_available(
             ['Outputs', 'lambdaArn', 'Value', 'Fn::GetAtt', ['LambdaExecutionRole', 'Arn']],
             'LambdaExecutionRole'
         ),
         [{'isPrimary': False}]
     )
     # Doesn't fail when the Path doesn't exist.  Still shows an error based on the fact there
     # are no conditions in the path that is workable
     self.assertEqual(
         template.is_resource_available(
             ['Resources', 'AMIIDLookup', 'Properties', 'BadProperty',
                 'Fn::If', 1, 'Fn::GetAtt', ['LambdaExecutionRole', 'Arn']],
             'LambdaExecutionRole'
         ),
         [{'isPrimary': False}]
     )
     # Gives appropriate response when there is no condition in path
     self.assertEqual(
         template.is_resource_available(
             ['Resources', 'AMIIDLookup', 'Properties', 'Handler'],
             'LambdaExecutionRole'
         ),
         [{'isPrimary': False}]
     )