Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion awscli/customizations/cloudformation/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ def create_changeset(self, stack_name, cfn_template,
# Each changeset will get a unique name based on time
changeset_name = self.changeset_prefix + str(int(time.time()))

changeset_type = "UPDATE"
if not self.has_stack(stack_name):
changeset_type = "CREATE"
# When creating a new stack, UsePreviousValue=True is invalid.
# For such parameters, users should either override with new value,
# or set a Default value in template to successfully create a stack.
parameter_values = [x for x in parameter_values
if not x.get("UsePreviousValue", False)]
else:
changeset_type = "UPDATE"
# UsePreviousValue not valid if parameter is new
summary = self._client.get_template_summary(StackName=stack_name)
existing_parameters = [parameter['ParameterKey'] for parameter in \
summary['Parameters']]
parameter_values = [x for x in parameter_values
if not (x.get("UsePreviousValue", False) and \
x["ParameterKey"] not in existing_parameters)]

kwargs = {
'ChangeSetName': changeset_name,
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/customizations/cloudformation/test_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,18 @@ def test_create_changeset_success(self):

# Case 2: Stack exists. We are updating it
self.deployer.has_stack.return_value = True
self.stub_client.add_response("get_template_summary",
{"Parameters": [{"ParameterKey": parameter["ParameterKey"]}
for parameter in parameters]},
{"StackName": stack_name})
expected_params["ChangeSetType"] = "UPDATE"
expected_params["Parameters"] = parameters
self.stub_client.add_response("create_change_set", response,
expected_params)
# template has new parameter but should not be included in
# expected_params as no previous value
parameters = list(parameters) + \
[{"ParameterKey": "New", "UsePreviousValue": True}]
with self.stub_client:
result = self.deployer.create_changeset(
stack_name, template, parameters, capabilities, role_arn,
Expand Down