# Buggy code
def change_value_in_dict(target_dictionary, path_to_change, value_to_change):
    if type(path_to_change) is str:
        path_to_change = path_to_change.split(".")

    if type(path_to_change) is not list:
        return False

    path_to_adjust = '["{}"]'.format('"]["'.join(path_to_change))

    try:
        target = eval("target_dictionary{}".format(path_to_adjust))

        for key, value in value_to_change.items():
            if "type" in value:
                type_key = value["type"]
                source = value
                source["referenced_name"] = key

                if type_key not in target:
                    target[type_key] = list()
                elif type_key in target and type(target[type_key]) is not list:
                    target[type_key] = [target[type_key]]

                target[type_key].append(source)

        target.update(value_to_change)

        try:
            exec("target_dictionary{}.update({})".format(path_to_adjust, target))
        except:
            # Yes I know, this is against PEP8.
            pass

    except KeyError:
        pass


# Traceback (SyntaxError)
terraform-compliance v0.4.11 initiated
Steps    : /usr/local/lib/python2.7/site-packages/terraform_compliance/steps
Features : /Users/demianginther/git/tf-modules/compliance
TF Files : /var/folders/zf/f1h382nn35z3gd1kv92bw6r80000gn/T/tmpxTN1V9 (.)
Reading terraform files.
All HCL files look good.
Running tests.
Feature: Resources should be properly tagged  # /Users/demianginther/git/tf-modules/compliance/tags.feature
In order to keep track of resource ownership
As engineers
We'll enforce tagging on all resources
1 features (0 passed)
1 scenarios (0 passed)
3 steps (0 passed)
Run 1547251063 finished within a moment
Error: Hook 'load_terraform_data' from /usr/local/lib/python2.7/site-packages/terraform_compliance/steps/terrain.py:6 raised: 'SyntaxError: invalid syntax (<string>, line 1)'

Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/radish/hookregistry.py", line 121, in call
func(model, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/terraform_compliance/steps/terrain.py", line 12, in load_terraform_data
enable_resource_mounting(tf_conf.terraform_config)
File "/usr/local/lib/python2.7/site-packages/terraform_compliance/extensions/terraform_validate.py", line 29, in enable_resource_mounting
enable_resource_mounting(tf_conf, sub_value, sub_resource)
File "/usr/local/lib/python2.7/site-packages/terraform_compliance/extensions/terraform_validate.py", line 29, in enable_resource_mounting
enable_resource_mounting(tf_conf, sub_value, sub_resource)
File "/usr/local/lib/python2.7/site-packages/terraform_compliance/extensions/terraform_validate.py", line 37, in enable_resource_mounting
change_value_in_dict(tf_conf, target, {source: processing_resource})
File "/usr/local/lib/python2.7/site-packages/terraform_compliance/common/helper.py", line 119, in change_value_in_dict
target = eval('target_dictionary{}'.format(path_to_adjust))
File "<string>", line 1
target_dictionary["resource"]["!var"]["alb_enabled &amp;&amp; !var"]["double_elb_listener_enabled &amp;&amp; var"]["env == "prod" ? 1 : 0"]
^
SyntaxError: invalid syntax

# Fixed code
def change_value_in_dict(target_dictionary, path_to_change, value_to_change):
    if type(path_to_change) is str:
        path_to_change = path_to_change.split(".")

    if type(path_to_change) is not list:
        return False

    for x in xrange(0, len(path_to_change)):
        for condition in hcl_conditions:
            if condition in path_to_change[x]:
                return False

    path_to_adjust = '["{}"]'.format('"]["'.join(path_to_change))

    try:
        target = eval("target_dictionary{}".format(path_to_adjust))

        for key, value in value_to_change.items():
            if "type" in value:
                type_key = value["type"]
                source = value
                source["referenced_name"] = key

                if type_key not in target:
                    target[type_key] = list()
                elif type_key in target and type(target[type_key]) is not list:
                    target[type_key] = [target[type_key]]

                target[type_key].append(source)

        target.update(value_to_change)

        try:
            exec("target_dictionary{}.update({})".format(path_to_adjust, target))
        except:
            # Yes I know, this is against PEP8.
            pass

    except KeyError:
        pass