in control-plane/custom-resources/src_macro/index.py [0:0]
def process_template(template, parameters):
"""Process the CloudFormation template.
Parameters
----------
template : JSON
Input template that is going to be transformed.
parameters : list
Additional parameters for the processing.
Returns
-------
type
status (success|failed), processed template
"""
new_template = copy.deepcopy(template)
status = 'success'
# Iterate over each of the CloudFormation created resources
for name, resource in template['Resources'].items():
# Check whether the current resource has the 'count' property
if 'Count' in resource:
try:
ref_value = new_template['Resources'][name]['Count'].pop('Ref')
# Convert referenced parameter to an integer value
count = int(parameters[ref_value])
# Remove the Count property from this resource
new_template['Resources'][name].pop('Count')
except AttributeError:
# Use numeric count value
count = new_template['Resources'][name].pop('Count')
print("Found 'Count' property with value {} in '{}'"
"resource.... multiplying!".format(count, name))
# Remove the original resource from the template
# but preserve a local copy of it
resourceToMultiply = new_template['Resources'].pop(name)
# Create a new block of the resource multiplied with names
# ending in the iterator and the placeholders substituted
resourcesAfterMultiplication = multiply(name, resourceToMultiply, count)
if not set(resourcesAfterMultiplication.keys()) & set(new_template['Resources'].keys()):
new_template['Resources'].update(resourcesAfterMultiplication)
else:
status = 'failed'
return status, template
else:
print("Did not find 'Count' property in"
"'{}' resource.... "
"Nothing to do!".format(name))
return status, new_template