Added resource deletion upon stack deletion

Only implemented for ASGs and LCs since they're all we cared about for
our particular problem. It should be easy to follow this pattern for
other resource types, though.

Signed-off-by: Scott Greene <scott.greene@getbraintree.com>
This commit is contained in:
Andrew Garrett 2016-02-29 19:50:29 +00:00 committed by Scott Greene
parent 993087f2bb
commit 39d9fbcd02
3 changed files with 21 additions and 3 deletions

View File

@ -80,6 +80,10 @@ class FakeLaunchConfiguration(object):
)
return config
def delete(self, region_name):
backend = autoscaling_backends[region_name]
backend.delete_launch_configuration(self.name)
@property
def physical_resource_id(self):
return self.name
@ -167,6 +171,10 @@ class FakeAutoScalingGroup(object):
)
return group
def delete(self, region_name):
backend = autoscaling_backends[region_name]
backend.delete_autoscaling_group(self.name)
@property
def physical_resource_id(self):
return self.name

View File

@ -52,6 +52,10 @@ class FakeStack(object):
self.resource_map.update(json.loads(template))
self.output_map = self._create_output_map()
def delete(self):
self.resource_map.delete()
self.status = 'DELETE_COMPLETE'
class CloudFormationBackend(BaseBackend):
@ -112,13 +116,14 @@ class CloudFormationBackend(BaseBackend):
if name_or_stack_id in self.stacks:
# Delete by stack id
stack = self.stacks.pop(name_or_stack_id, None)
stack.status = 'DELETE_COMPLETE'
stack.delete()
self.deleted_stacks[stack.stack_id] = stack
return self.stacks.pop(name_or_stack_id, None)
else:
# Delete by stack name
stack_to_delete = [stack for stack in self.stacks.values() if stack.name == name_or_stack_id][0]
self.delete_stack(stack_to_delete.stack_id)
for stack in list(self.stacks.values()):
if stack.name == name_or_stack_id:
self.delete_stack(stack.stack_id)
cloudformation_backends = {}

View File

@ -374,6 +374,11 @@ class ResourceMap(collections.Mapping):
changed_resource = parse_and_update_resource(resource_name, resource_json, self, self._region_name)
self._parsed_resources[resource_name] = changed_resource
def delete(self):
for resource in self.resources:
parsed_resource = self._parsed_resources.pop(resource)
parsed_resource.delete(self._region_name)
class OutputMap(collections.Mapping):
def __init__(self, resources, template):