From e7c07fbd13380bcf47c44d2e519a2a148a59afd9 Mon Sep 17 00:00:00 2001 From: Justin McCormick Date: Thu, 2 Mar 2023 03:58:02 -0600 Subject: [PATCH] ecs_service -- with force_new_deployment user can specify taskdef or not (#1680) ecs_service -- with force_new_deployment user can specify taskdef or not SUMMARY Fixes #1106 Support force_new_deployment without having to specify a task definition. ISSUE TYPE Feature Pull Request COMPONENT NAME ecs_service ADDITIONAL INFORMATION Previously task_definition was required when state was present; regardless of whether force_new_deployment was set or not. Previous error was along the lines of "state is present but all of the following are missing: task_definition". New behavior enforces either task_definition or force_new_deployment is set. If both are provided, the user's task_definition will be sent through to boto. If only task_definition is defined, original behavior resumes. If only force_new_deployment is set, pull the taskDefinition from existing and pass it through to boto. Reviewed-by: Alina Buzachis Reviewed-by: Mark Chappell Reviewed-by: Markus Bergholz --- ecs_service.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ecs_service.py b/ecs_service.py index 928d03b4386..15c74b92c50 100644 --- a/ecs_service.py +++ b/ecs_service.py @@ -44,7 +44,7 @@ task_definition: description: - The task definition the service will run. - - This parameter is required when I(state=present). + - This parameter is required when I(state=present) unless I(force_new_deployment=True). - This parameter is ignored when updating a service with a C(CODE_DEPLOY) deployment controller in which case the task definition is managed by Code Pipeline and cannot be updated. required: false @@ -971,14 +971,15 @@ def main(): module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True, - required_if=[('state', 'present', ['task_definition']), - ('launch_type', 'FARGATE', ['network_configuration'])], + required_if=[('launch_type', 'FARGATE', ['network_configuration'])], required_together=[['load_balancers', 'role']], mutually_exclusive=[['launch_type', 'capacity_provider_strategy']]) - if module.params['state'] == 'present' and module.params['scheduling_strategy'] == 'REPLICA': - if module.params['desired_count'] is None: + if module.params['state'] == 'present': + if module.params['scheduling_strategy'] == 'REPLICA' and module.params['desired_count'] is None: module.fail_json(msg='state is present, scheduling_strategy is REPLICA; missing desired_count') + if module.params['task_definition'] is None and not module.params['force_new_deployment']: + module.fail_json(msg='Either task_definition or force_new_deployment is required when status is present.') if len(module.params['capacity_provider_strategy']) > 6: module.fail_json(msg='AWS allows a maximum of six capacity providers in the strategy.') @@ -1075,6 +1076,9 @@ def main(): updatedLoadBalancers = loadBalancers if existing['deploymentController']['type'] == 'ECS' else [] + if task_definition is None and module.params['force_new_deployment']: + task_definition = existing['taskDefinition'] + # update required response = service_mgr.update_service(module.params['name'], module.params['cluster'],