diff --git a/src/cfnlint/template.py b/src/cfnlint/template.py index 8c1e6a5e99..b88e8eb3ed 100644 --- a/src/cfnlint/template.py +++ b/src/cfnlint/template.py @@ -201,19 +201,21 @@ def get_valid_getatts(self): def get_directives(self): results = {} - for resource_name, resource_values in self.template.get('Resources', {}).items(): - if isinstance(resource_values, dict): - ignore_rule_ids = resource_values.get('Metadata', {}).get( - 'cfn-lint', {}).get('config', {}).get('ignore_checks', []) - for ignore_rule_id in ignore_rule_ids: - if ignore_rule_id not in results: - results[ignore_rule_id] = [] - value_location = self._loc(resource_values) - name_location = self._loc(resource_name) - results[ignore_rule_id].append({ - 'start': (name_location[0] + 1, name_location[1] + 1), - 'end': (value_location[2] + 1, value_location[3] + 1), - }) + resources = self.get_resources() + if resources: + for resource_name, resource_values in resources.items(): + if isinstance(resource_values, dict): + ignore_rule_ids = resource_values.get('Metadata', {}).get( + 'cfn-lint', {}).get('config', {}).get('ignore_checks', []) + for ignore_rule_id in ignore_rule_ids: + if ignore_rule_id not in results: + results[ignore_rule_id] = [] + value_location = self._loc(resource_values) + name_location = self._loc(resource_name) + results[ignore_rule_id].append({ + 'start': (name_location[0] + 1, name_location[1] + 1), + 'end': (value_location[2] + 1, value_location[3] + 1), + }) return results def _get_sub_resource_properties(self, keys, properties, path):