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

Support changing of launch type #840

Merged
Show file tree
Hide file tree
Changes from 4 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 @@
bugfixes:
- ecs_taskdefinition - include launch_type comparison when comparing task definitions (https://github.com/ansible-collections/community.aws/pull/840)
8 changes: 6 additions & 2 deletions plugins/modules/ecs_taskdefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,13 +924,16 @@ def _right_has_values_of_left(left, right):

return True

def _task_definition_matches(requested_volumes, requested_containers, requested_task_role_arn, existing_task_definition):
def _task_definition_matches(requested_volumes, requested_containers, requested_task_role_arn, requested_launch_type, existing_task_definition):
if td['status'] != "ACTIVE":
return None

if requested_task_role_arn != td.get('taskRoleArn', ""):
return None

if requested_launch_type not in td.get('requiresCompatibilities', []):
return None

existing_volumes = td.get('volumes', []) or []

if len(requested_volumes) != len(existing_volumes):
Expand Down Expand Up @@ -973,7 +976,8 @@ def _task_definition_matches(requested_volumes, requested_containers, requested_
requested_volumes = module.params['volumes'] or []
requested_containers = module.params['containers'] or []
requested_task_role_arn = module.params['task_role_arn']
existing = _task_definition_matches(requested_volumes, requested_containers, requested_task_role_arn, td)
requested_launch_type = module.params['launch_type']
existing = _task_definition_matches(requested_volumes, requested_containers, requested_task_role_arn, requested_launch_type, td)

if existing:
break
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/targets/ecs_cluster/tasks/full_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,29 @@
ecs_taskdefinition_info:
task_definition: "{{ ecs_task_name }}-vpc:{{ ecs_fargate_task_definition.taskdefinition.revision }}"

- name: create EC2 VPC-networked task definition with CPU or Memory and execution role
ecs_taskdefinition:
containers: "{{ ecs_fargate_task_containers }}"
family: "{{ ecs_task_name }}-vpc"
network_mode: awsvpc
launch_type: EC2
cpu: 512
memory: 1024
execution_role_arn: "{{ iam_execution_role.arn }}"
state: present
vars:
ecs_task_host_port: 8080
register: ecs_ec2_task_definition

- name: obtain ECS task definition facts
ecs_taskdefinition_info:
task_definition: "{{ ecs_task_name }}-vpc:{{ ecs_ec2_task_definition.taskdefinition.revision }}"

- name: check that changing task definiton launch type created a new task definition revision
assert:
that:
- ecs_fargate_task_definition.taskdefinition.revision != ecs_ec2_task_definition.taskdefinition.revision

- name: create fargate ECS service without network config (expected to fail)
ecs_service:
state: present
Expand Down