diff --git a/moto/autoscaling/models.py b/moto/autoscaling/models.py index d7f0db620..5a044c038 100644 --- a/moto/autoscaling/models.py +++ b/moto/autoscaling/models.py @@ -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 diff --git a/moto/cloudformation/models.py b/moto/cloudformation/models.py index cd99856f5..d8793b8ea 100644 --- a/moto/cloudformation/models.py +++ b/moto/cloudformation/models.py @@ -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 = {} diff --git a/moto/cloudformation/parsing.py b/moto/cloudformation/parsing.py index ebdd83634..32b9f351f 100644 --- a/moto/cloudformation/parsing.py +++ b/moto/cloudformation/parsing.py @@ -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):