Example #1
0
    def update_vertex_config(vertex, changed_attributes):
        updated_config = deepcopy(vertex.config)
        if vertex.block_type != BlockType.LOCALS:
            parts = vertex.name.split('.')
            start = 0
            end = 1
            while end <= len(parts):
                cur_key = '.'.join(parts[start:end])
                if cur_key in updated_config:
                    updated_config = updated_config[cur_key]
                    start = end
                end += 1
        for changed_attribute in changed_attributes:
            new_value = vertex.attributes.get(changed_attribute, None)
            if new_value is not None:
                if vertex.block_type == BlockType.LOCALS:
                    changed_attribute = changed_attribute.replace(
                        vertex.name + ".", '')
                updated_config = update_dictionary_attribute(
                    updated_config, changed_attribute, new_value)

        if len(changed_attributes) > 0:
            if vertex.block_type == BlockType.LOCALS:
                updated_config = updated_config.get(vertex.name)
            update_dictionary_attribute(vertex.config, vertex.name,
                                        updated_config)
Example #2
0
 def test_update_dictionary_attribute_nested(self):
     origin_config = {
         'aws_s3_bucket': {
             'destination': {
                 'bucket': ['tf-test-bucket-destination-12345'],
                 'acl': ['${var.acl}'],
                 'versioning': [{
                     'enabled': ['${var.is_enabled}']
                 }]
             }
         }
     }
     key_to_update = 'versioning.enabled'
     new_value = [False]
     expected_config = {
         'aws_s3_bucket': {
             'destination': {
                 'bucket': ['tf-test-bucket-destination-12345'],
                 'acl': ['${var.acl}'],
                 'versioning': [{
                     'enabled': [False]
                 }]
             }
         }
     }
     actual_config = update_dictionary_attribute(origin_config,
                                                 key_to_update, new_value)
     self.assertEqual(
         expected_config, actual_config,
         f'failed to update config. expected: {expected_config}, got: {actual_config}'
     )
Example #3
0
    def update_vertex_config(vertex, changed_attributes):
        updated_config = deepcopy(vertex.config)
        if vertex.block_type != BlockType.LOCALS:
            for name_part in vertex.name.split('.'):
                updated_config = updated_config.get(name_part)
        for changed_attribute in changed_attributes:
            new_value = vertex.attributes.get(changed_attribute, None)
            if new_value is not None:
                if vertex.block_type == BlockType.LOCALS:
                    changed_attribute = changed_attribute.replace(
                        vertex.name + ".", '')
                updated_config = update_dictionary_attribute(
                    updated_config, changed_attribute, new_value)

        if len(changed_attributes) > 0:
            if vertex.block_type == BlockType.LOCALS:
                updated_config = updated_config.get(vertex.name)
            update_dictionary_attribute(vertex.config, vertex.name,
                                        updated_config)