Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ECS.Client.delete_service to force delete a service #228

Merged
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
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