Fix failure in ARM templates
import logging
import operator
-from functools import reduce
import re
+from functools import reduce
# COMMENT_REGEX = re.compile(r'(checkov:skip=) *([A-Z_\d]+)(:[^\n]+)?')
COMMENT_REGEX = re.compile(r'([A-Z_\d]+)(:[^\n]+)?')
+
class ContextParser(object):
"""
ARM template context parser
"""
+
def __init__(self, arm_file, arm_template, arm_template_lines):
self.arm_file = arm_file
self.arm_template = arm_template
@@ -52,6 +54,7 @@ class ContextParser(object):
logging.debug(e, stack_info=True)
for key_entry in keys_w_vars:
+ try:
param = re.sub("\[variables\('|'\)]", "", self._get_from_dict(dict(self.arm_template),
key_entry[:-1])[key_entry[-1]])
if param in variable_values.keys():
@@ -61,8 +64,9 @@ class ContextParser(object):
variable_values[param]))
else:
logging.debug("Variable {} not found in evaluated variables in file {}".format(param, self.arm_file))
-
-
+ except TypeError as e:
+ logging.debug(f'Failed to evaluate param in {self.arm_file}, error:')
+ logging.debug(e, stack_info=True)
@staticmethod
def extract_arm_resource_id(arm_resource):
