Allow CloudFormation stack tags to be updated
Limitations: * does not update the tags of the resources in the stack. that can be implemented later. * does not support the supposed feature of clearing tags by passing an empty value that boto3 mentions in its documentation. I could not find anything in the request body to indicate when an empty value was passed.
This commit is contained in:
parent
a6e762340d
commit
6f4cb512ac
4 changed files with 43 additions and 6 deletions
|
|
@ -82,7 +82,7 @@ class FakeStack(BaseModel):
|
|||
def stack_outputs(self):
|
||||
return self.output_map.values()
|
||||
|
||||
def update(self, template, role_arn=None, parameters=None):
|
||||
def update(self, template, role_arn=None, parameters=None, tags=None):
|
||||
self._add_stack_event("UPDATE_IN_PROGRESS", resource_status_reason="User Initiated")
|
||||
self.template = template
|
||||
self.resource_map.update(json.loads(template), parameters)
|
||||
|
|
@ -90,6 +90,10 @@ class FakeStack(BaseModel):
|
|||
self._add_stack_event("UPDATE_COMPLETE")
|
||||
self.status = "UPDATE_COMPLETE"
|
||||
self.role_arn = role_arn
|
||||
# only overwrite tags if passed
|
||||
if tags is not None:
|
||||
self.tags = tags
|
||||
# TODO: update tags in the resource map
|
||||
|
||||
def delete(self):
|
||||
self._add_stack_event("DELETE_IN_PROGRESS",
|
||||
|
|
@ -164,9 +168,9 @@ class CloudFormationBackend(BaseBackend):
|
|||
if stack.name == name_or_stack_id:
|
||||
return stack
|
||||
|
||||
def update_stack(self, name, template, role_arn=None, parameters=None):
|
||||
def update_stack(self, name, template, role_arn=None, parameters=None, tags=None):
|
||||
stack = self.get_stack(name)
|
||||
stack.update(template, role_arn, parameters=parameters)
|
||||
stack.update(template, role_arn, parameters=parameters, tags=tags)
|
||||
return stack
|
||||
|
||||
def list_stack_resources(self, stack_name_or_id):
|
||||
|
|
|
|||
|
|
@ -152,6 +152,14 @@ class CloudFormationResponse(BaseResponse):
|
|||
for parameter
|
||||
in self._get_list_prefix("Parameters.member")
|
||||
])
|
||||
# boto3 is supposed to let you clear the tags by passing an empty value, but the request body doesn't
|
||||
# end up containing anything we can use to differentiate between passing an empty value versus not
|
||||
# passing anything. so until that changes, moto won't be able to clear tags, only update them.
|
||||
tags = dict((item['key'], item['value'])
|
||||
for item in self._get_list_prefix("Tags.member"))
|
||||
# so that if we don't pass the parameter, we don't clear all the tags accidentally
|
||||
if not tags:
|
||||
tags = None
|
||||
|
||||
stack = self.cloudformation_backend.get_stack(stack_name)
|
||||
if stack.status == 'ROLLBACK_COMPLETE':
|
||||
|
|
@ -162,7 +170,8 @@ class CloudFormationResponse(BaseResponse):
|
|||
name=stack_name,
|
||||
template=stack_body,
|
||||
role_arn=role_arn,
|
||||
parameters=parameters
|
||||
parameters=parameters,
|
||||
tags=tags,
|
||||
)
|
||||
if self.request_json:
|
||||
stack_body = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue