Skip to content

Commit

Permalink
ecs_service -- with force_new_deployment user can specify taskdef or …
Browse files Browse the repository at this point in the history
…not (ansible-collections#1680)

ecs_service -- with force_new_deployment user can specify taskdef or not

SUMMARY
Fixes ansible-collections#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 <git@osuv.de>
  • Loading branch information
karcadia authored Mar 2, 2023
1 parent d190cf1 commit e7c07fb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ecs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.')
Expand Down Expand Up @@ -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'],
Expand Down

0 comments on commit e7c07fb

Please sign in to comment.