Skip to content

Commit

Permalink
Allow ECS.Client.delete_service to force delete a service (#228)
Browse files Browse the repository at this point in the history
Allow ECS.Client.delete_service to force delete a service

SUMMARY
Change allows ansible to forcefully delete a service,
required when deleting a service with >0 scale, or no target group
ISSUE TYPE
#220
COMPONENT NAME
ecs_service

Reviewed-by: None <None>
  • Loading branch information
asaf400 authored Oct 22, 2021
1 parent 8fe00cb commit 458177c
Show file tree
Hide file tree
Showing 4 changed files with 780 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/228-ecs_service-force_delete.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ecs_service - added support for forcing deletion of a service (https://github.com/ansible-collections/community.aws/pull/228).
14 changes: 11 additions & 3 deletions plugins/modules/ecs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@
field:
description: The field to apply the placement strategy against.
type: str
force_deletion:
description:
- Forcabily delete the service. Required when deleting a service with >0 scale, or no target group.
default: False
type: bool
version_added: 2.1.0
network_configuration:
description:
- Network configuration of the service. Only applicable for task definitions created with I(network_mode=awsvpc).
Expand Down Expand Up @@ -631,8 +637,8 @@ def jsonize(self, service):
e['createdAt'] = str(e['createdAt'])
return service

def delete_service(self, service, cluster=None):
return self.ecs.delete_service(cluster=cluster, service=service)
def delete_service(self, service, cluster=None, force=False):
return self.ecs.delete_service(cluster=cluster, service=service, force=force)

def health_check_setable(self, params):
load_balancers = params.get('loadBalancers', [])
Expand All @@ -652,6 +658,7 @@ def main():
delay=dict(required=False, type='int', default=10),
repeat=dict(required=False, type='int', default=10),
force_new_deployment=dict(required=False, default=False, type='bool'),
force_deletion=dict(required=False, default=False, type='bool'),
deployment_configuration=dict(required=False, default={}, type='dict'),
placement_constraints=dict(
required=False,
Expand Down Expand Up @@ -810,7 +817,8 @@ def main():
try:
service_mgr.delete_service(
module.params['name'],
module.params['cluster']
module.params['cluster'],
module.params['force_deletion'],
)
except botocore.exceptions.ClientError as e:
module.fail_json_aws(e, msg="Couldn't delete service")
Expand Down
Loading

0 comments on commit 458177c

Please sign in to comment.