From 21d6a8ebf0642a0adf14299e9a09f72dd5e5dbea Mon Sep 17 00:00:00 2001 From: mattmb Date: Tue, 14 Apr 2015 10:19:18 +0100 Subject: [PATCH] Fix include merging. This commit fixes a couple of mistakes in the merging code for included cloudformation templates. It also makes the documentation clearer on how the merge works. --- README.rst | 2 +- bootstrap_cfn/config.py | 2 +- bootstrap_cfn/utils.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 7b76440..916cb8c 100644 --- a/README.rst +++ b/README.rst @@ -136,4 +136,4 @@ If you wish to include some static cloudformation json and have it merged with t includes: - /path/to/cloudformation.json -The tool will then merge this with the generated template *overwriting* any keys in the original template that clash. +The tool will then perform a deep merge of the includes with the generated template dictionary. Any keys or subkeys in the template dictionary that clash will have their values **overwritten** by the included dictionary or recursively merged if the value is itself a dictionary. diff --git a/bootstrap_cfn/config.py b/bootstrap_cfn/config.py index 149ed89..718ffdc 100644 --- a/bootstrap_cfn/config.py +++ b/bootstrap_cfn/config.py @@ -79,7 +79,7 @@ def process(self): if 'includes' in self.data: for inc_path in self.data['includes']: inc = json.load(open(inc_path)) - utils.dict_merge(template, inc) + template = utils.dict_merge(template, inc) return json.dumps( template, sort_keys=True, indent=4, separators=(',', ': ')) diff --git a/bootstrap_cfn/utils.py b/bootstrap_cfn/utils.py index 4c58adc..981676d 100644 --- a/bootstrap_cfn/utils.py +++ b/bootstrap_cfn/utils.py @@ -57,7 +57,7 @@ def dict_merge(target, *args): # Merge multiple dicts if len(args) > 1: for obj in args: - self.dict_merge(target, obj) + dict_merge(target, obj) return target # Recursively merge dicts and set non-dict values