def enable_resource_mounting(tf_conf, processing_resource=None, resource=None):
    if not resource:
        resource = 'resource'
    else:
        resource = resource.strip()

    if not processing_resource:
        if resource not in tf_conf:
            return

        processing_resource = tf_conf[resource]

    source = resource.strip()
    source = (source[:-3] if source.endswith('.id') else source)

    for sub_resource, sub_value in processing_resource.items():

        if type(sub_value) is dict:
            enable_resource_mounting(tf_conf, sub_value, sub_resource)
        else:
            regex = r'\${(.*)\}'
            if type(sub_value) is str or type(sub_value) is unicode:
                matches = re.match(regex, sub_value)

                if matches is not None and not matches.group(1).startswith(
                    ('var', 'data', 'module')) and '(' not in matches.group(1):
                    target = generate_target_resource(matches.group(1))
                    change_value_in_dict(tf_conf, target,
                                         {source: processing_resource})

            elif type(sub_value) is list:
                for value in sub_value:
                    if type(value) is str or type(value) is unicode:
                        matches = re.match(regex, value)
                        if matches is not None and not matches.group(
                                1).startswith(
                                    ('var', 'data', 'module'
                                     )) and '(' not in matches.group(1):
                            target = generate_target_resource(matches.group(1))
                            change_value_in_dict(tf_conf, target,
                                                 {source: processing_resource})
Ejemplo n.º 2
0
 def test_generate_target_resource_has_id_and_name_in_it(self):
     self.assertEqual(['resource', 'target', 'test'],
                      generate_target_resource('target.test.id'))
     self.assertEqual(['resource', 'target', 'test'],
                      generate_target_resource('target.test.name'))
Ejemplo n.º 3
0
 def test_generate_target_resource(self):
     self.assertEqual(['resource', 'target', 'test'],
                      generate_target_resource('target.test'))