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

ecs_service -- with force_new_deployment user can specify taskdef or not #1680

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ecs_service - ``task_definition`` is now optional when ``force_new_deployment`` is ``True`` (https://github.com/ansible-collections/community.aws/pull/1680).
14 changes: 9 additions & 5 deletions plugins/modules/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
26 changes: 26 additions & 0 deletions tests/integration/targets/ecs_cluster/tasks/20_ecs_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,32 @@
that:
- ecs_service_again.changed

- name: force_new_deployment should work without providing a task_definition
vars:
ansible_python_interpreter: "{{ botocore_virtualenv_interpreter }}"
ecs_service:
state: present
force_new_deployment: yes
name: "{{ ecs_service_name }}"
cluster: "{{ ecs_cluster_name }}"
desired_count: 1
deployment_configuration: "{{ ecs_service_deployment_configuration }}"
placement_strategy: "{{ ecs_service_placement_strategy }}"
placement_constraints:
- type: distinctInstance
health_check_grace_period_seconds: "{{ ecs_service_health_check_grace_period }}"
load_balancers:
- targetGroupArn: "{{ elb_target_group_instance.target_group_arn }}"
containerName: "{{ ecs_task_name }}"
containerPort: "{{ ecs_task_container_port }}"
role: "{{ ecs_service_role_name }}"
register: ecs_service_notaskdef

- name: check that ECS service changed again due to force_new_deployment with no task definition
assert:
that:
- ecs_service_notaskdef.changed

- name: attempt to use ECS network configuration on task definition without awsvpc network_mode (expected to fail)
vars:
ansible_python_interpreter: "{{ botocore_virtualenv_interpreter }}"
Expand Down