Skip to content

Commit

Permalink
Support changing of launch type (#840)
Browse files Browse the repository at this point in the history
Support changing of launch type

SUMMARY
When changing the launch_type parameter for an ecs_taskdefition there was no change reported by the module. This adds a check to see if launch_type in the ecs_taskdefinition has changed. If there is a change detected the module reports back there is not a matching task definition and creates a new one.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
ecs_taskdefinition

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Michael Mayer <[email protected]>
Reviewed-by: Markus Bergholz <[email protected]>
  • Loading branch information
mjmayer authored Mar 18, 2022
1 parent e965b23 commit c67c890
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
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 @@ -923,13 +923,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 is not None and requested_launch_type not in td.get('compatibilities', []):
return None

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

if len(requested_volumes) != len(existing_volumes):
Expand Down Expand Up @@ -972,7 +975,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

0 comments on commit c67c890

Please sign in to comment.