From 0466af3b9f477fbd8e67b676525d958eb2c8af2f Mon Sep 17 00:00:00 2001 From: Joseph Torcasso <87090265+jatorcasso@users.noreply.github.com> Date: Wed, 8 Jun 2022 07:50:35 -0400 Subject: [PATCH] ecs_* - fix idempotence bug in ecs_service and dont require ``cluster`` (#1212) ecs_* - fix idempotence bug in ecs_service and dont require ``cluster`` SUMMARY Don't require cluster param and use cluster name 'default' when not specified (see docs). Fix bug when comparing health_check_grace_period_seconds when not input by user. ISSUE TYPE Bugfix Pull Request COMPONENT NAME ecs_service ecs_task ADDITIONAL INFORMATION Split up from #1209 to backport to stable-2 Reviewed-by: Markus Bergholz Reviewed-by: Alina Buzachis (cherry picked from commit bac247365347a6b6e4f90c8087f235b01cf8d253) --- .../1212-ecs_service-fix-broken-change-detect.yml | 4 ++++ plugins/modules/ecs_service.py | 9 ++++++--- plugins/modules/ecs_task.py | 6 ++++-- 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/1212-ecs_service-fix-broken-change-detect.yml diff --git a/changelogs/fragments/1212-ecs_service-fix-broken-change-detect.yml b/changelogs/fragments/1212-ecs_service-fix-broken-change-detect.yml new file mode 100644 index 00000000000..78618b78466 --- /dev/null +++ b/changelogs/fragments/1212-ecs_service-fix-broken-change-detect.yml @@ -0,0 +1,4 @@ +bugfixes: + - ecs_service - fix broken change detect of ``health_check_grace_period_seconds`` parameter when not specified (https://github.com/ansible-collections/community.aws/pull/1212). + - ecs_service - use default cluster name of ``default`` when not input (https://github.com/ansible-collections/community.aws/pull/1212). + - ecs_task - dont require ``cluster`` and use name of ``default`` when not input (https://github.com/ansible-collections/community.aws/pull/1212). diff --git a/plugins/modules/ecs_service.py b/plugins/modules/ecs_service.py index ea90e9bb1ae..0dc2911d918 100644 --- a/plugins/modules/ecs_service.py +++ b/plugins/modules/ecs_service.py @@ -38,8 +38,10 @@ cluster: description: - The name of the cluster in which the service exists. + - If not specified, the cluster name will be C(default). required: false type: str + default: 'default' task_definition: description: - The task definition the service will run. @@ -595,8 +597,9 @@ def is_matching_service(self, expected, existing): if expected['task_definition'] != existing['taskDefinition'].split('/')[-1]: return False - if expected.get('health_check_grace_period_seconds') != existing.get('healthCheckGracePeriodSeconds'): - return False + if expected.get('health_check_grace_period_seconds'): + if expected.get('health_check_grace_period_seconds') != existing.get('healthCheckGracePeriodSeconds'): + return False if (expected['load_balancers'] or []) != existing['loadBalancers']: return False @@ -701,7 +704,7 @@ def main(): argument_spec = dict( state=dict(required=True, choices=['present', 'absent', 'deleting']), name=dict(required=True, type='str', aliases=['service']), - cluster=dict(required=False, type='str'), + cluster=dict(required=False, type='str', default='default'), task_definition=dict(required=False, type='str'), load_balancers=dict(required=False, default=[], type='list', elements='dict'), desired_count=dict(required=False, type='int'), diff --git a/plugins/modules/ecs_task.py b/plugins/modules/ecs_task.py index b2ca36e21de..277bbe4770d 100644 --- a/plugins/modules/ecs_task.py +++ b/plugins/modules/ecs_task.py @@ -27,8 +27,10 @@ cluster: description: - The name of the cluster to run the task on. - required: True + - If not specified, the cluster name will be C(default). + required: False type: str + default: 'default' task_definition: description: - The task definition to start, run or stop. @@ -340,7 +342,7 @@ def ecs_task_long_format_enabled(self): def main(): argument_spec = dict( operation=dict(required=True, choices=['run', 'start', 'stop']), - cluster=dict(required=True, type='str'), # R S P + cluster=dict(required=False, type='str', default='default'), # R S P task_definition=dict(required=False, type='str'), # R* S* overrides=dict(required=False, type='dict'), # R S count=dict(required=False, type='int'), # R