From 1ed992857ace27791bb53a6576b9cd42da18e3b2 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 25 Oct 2022 19:20:00 -0700 Subject: [PATCH 1/5] Add check_id to return info on updating health check --- plugins/modules/route53_health_check.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/modules/route53_health_check.py b/plugins/modules/route53_health_check.py index 532bc82c3ba..0009b681e2e 100644 --- a/plugins/modules/route53_health_check.py +++ b/plugins/modules/route53_health_check.py @@ -425,6 +425,7 @@ def update_health_check(existing_check): changes = dict() existing_config = existing_check.get('HealthCheckConfig') + check_id = existing_check.get('Id') resource_path = module.params.get('resource_path', None) if resource_path and resource_path != existing_config.get('ResourcePath'): @@ -458,11 +459,10 @@ def update_health_check(existing_check): # No changes... if not changes: - return False, None + return False, None, check_id if module.check_mode: - return True, 'update' + return True, 'update', check_id - check_id = existing_check.get('Id') # This makes sure we're starting from the version we think we are... version_id = existing_check.get('HealthCheckVersion', 1) try: @@ -474,7 +474,7 @@ def update_health_check(existing_check): except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: module.fail_json_aws(e, msg='Failed to update health check.', id=check_id) - return True, 'update' + return True, 'update', check_id def describe_health_check(id): @@ -616,7 +616,7 @@ def main(): existing_checks_with_name = get_existing_checks_with_name() # update the health_check if another health check with same name exists if health_check_name in existing_checks_with_name: - changed, action = update_health_check(existing_checks_with_name[health_check_name]) + changed, action, check_id = update_health_check(existing_checks_with_name[health_check_name]) else: # create a new health_check if another health check with same name does not exists changed, action, check_id = create_health_check(ip_addr_in, fqdn_in, type_in, request_interval_in, port_in) @@ -628,9 +628,9 @@ def main(): else: if update_delete_by_id: - changed, action = update_health_check(existing_check) + changed, action, check_id = update_health_check(existing_check) else: - changed, action = update_health_check(existing_check) + changed, action, check_id = update_health_check(existing_check) if check_id: changed |= manage_tags(module, client, 'healthcheck', check_id, From cd318b4abf0c5b1efcd1e9a5d172d6fabb4189c6 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 25 Oct 2022 19:24:52 -0700 Subject: [PATCH 2/5] added changelogs fragment --- ...oute53_health_check-return-health-check-info-on-updating.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/1200-route53_health_check-return-health-check-info-on-updating.yml diff --git a/changelogs/fragments/1200-route53_health_check-return-health-check-info-on-updating.yml b/changelogs/fragments/1200-route53_health_check-return-health-check-info-on-updating.yml new file mode 100644 index 00000000000..c6585f53fbe --- /dev/null +++ b/changelogs/fragments/1200-route53_health_check-return-health-check-info-on-updating.yml @@ -0,0 +1,2 @@ +minor_changes: +- route53_health_check - minor fix for returning health check info while updating a Route53 health check (https://github.com/ansible-collections/amazon.aws/pull/1200). From 12502fb5b0507b8fbaa2ccecf5193fadc2c2917e Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Thu, 27 Oct 2022 14:49:32 -0700 Subject: [PATCH 3/5] Add integration test --- .../route53_health_check/defaults/main.yml | 1 + .../tasks/create_multiple_health_checks.yml | 54 ++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/route53_health_check/defaults/main.yml b/tests/integration/targets/route53_health_check/defaults/main.yml index 769e5079d1b..f93b45e57cd 100644 --- a/tests/integration/targets/route53_health_check/defaults/main.yml +++ b/tests/integration/targets/route53_health_check/defaults/main.yml @@ -13,6 +13,7 @@ fqdn: '{{ tiny_prefix }}.route53-health.ansible.test' fqdn_1: '{{ tiny_prefix }}-1.route53-health.ansible.test' port: 8080 +updated_port: 8181 type: 'TCP' request_interval: 30 diff --git a/tests/integration/targets/route53_health_check/tasks/create_multiple_health_checks.yml b/tests/integration/targets/route53_health_check/tasks/create_multiple_health_checks.yml index 42bdb6562a9..b2bc5984d9f 100644 --- a/tests/integration/targets/route53_health_check/tasks/create_multiple_health_checks.yml +++ b/tests/integration/targets/route53_health_check/tasks/create_multiple_health_checks.yml @@ -117,6 +117,46 @@ - '"route53:UpdateHealthCheck" not in create_idem.results[0].resource_actions' - '"route53:UpdateHealthCheck" not in create_idem.results[1].resource_actions' + - name: 'Update HTTP health checks with different resource_path' + route53_health_check: + state: present + name: '{{ tiny_prefix }}-{{ item }}-test-hc-delete-if-found' + ip_address: '{{ ip_address }}' + port: '{{ updated_port }}' + type: '{{ type_http }}' + resource_path: '{{ item }}' + use_unique_names: true + register: update_health_check + with_items: + - '{{ resource_path }}' + + - name: 'Check result - Update TCP health check - set threshold' + assert: + that: + - update_health_check is successful + - update_health_check is changed + - '"id" in _health_check' + - _health_check.id == health_check_1_id + - '"health_check_version" in _health_check' + - '"tags" in _health_check' + - '"health_check_config" in _health_check' + - '"type" in _check_config' + - '"disabled" in _check_config' + - '"failure_threshold" in _check_config' + - '"request_interval" in _check_config' + - '"fully_qualified_domain_name" not in _check_config' + - '"ip_address" in _check_config' + - '"port" in _check_config' + - '"search_string" not in _check_config' + - _check_config.disabled == false + - _check_config.type == 'HTTP' + - _check_config.request_interval == 30 + - _check_config.ip_address == ip_address + - _check_config.port == updated_port + vars: + _health_check: '{{ update_health_check.results[0].health_check }}' + _check_config: '{{ update_health_check.results[0].health_check.health_check_config }}' + always: # Cleanup starts here - name: 'Delete multiple HTTP health checks with different resource_path' @@ -124,11 +164,23 @@ state: absent name: '{{ tiny_prefix }}-{{ item }}-test-hc-delete-if-found' ip_address: '{{ ip_address }}' - port: '{{ port }}' + port: '{{ updated_port }}' type: '{{ type_http }}' resource_path: '{{ item }}' use_unique_names: true register: delete_result with_items: - '{{ resource_path }}' + + - name: 'Delete multiple HTTP health checks with different resource_path' + route53_health_check: + state: absent + name: '{{ tiny_prefix }}-{{ item }}-test-hc-delete-if-found' + ip_address: '{{ ip_address }}' + port: '{{ port }}' + type: '{{ type_http }}' + resource_path: '{{ item }}' + use_unique_names: true + register: delete_result + with_items: - '{{ resource_path_1 }}' From b5093a79e899494b4dc97b665eadae130c7822f8 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Thu, 27 Oct 2022 14:51:37 -0700 Subject: [PATCH 4/5] fix integration test task name --- .../tasks/create_multiple_health_checks.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/targets/route53_health_check/tasks/create_multiple_health_checks.yml b/tests/integration/targets/route53_health_check/tasks/create_multiple_health_checks.yml index b2bc5984d9f..9cd1dd53446 100644 --- a/tests/integration/targets/route53_health_check/tasks/create_multiple_health_checks.yml +++ b/tests/integration/targets/route53_health_check/tasks/create_multiple_health_checks.yml @@ -117,7 +117,7 @@ - '"route53:UpdateHealthCheck" not in create_idem.results[0].resource_actions' - '"route53:UpdateHealthCheck" not in create_idem.results[1].resource_actions' - - name: 'Update HTTP health checks with different resource_path' + - name: 'Update HTTP health check - update port' route53_health_check: state: present name: '{{ tiny_prefix }}-{{ item }}-test-hc-delete-if-found' @@ -130,7 +130,7 @@ with_items: - '{{ resource_path }}' - - name: 'Check result - Update TCP health check - set threshold' + - name: 'Check result - Update TCP health check - update port' assert: that: - update_health_check is successful @@ -159,7 +159,7 @@ always: # Cleanup starts here - - name: 'Delete multiple HTTP health checks with different resource_path' + - name: 'Delete HTTP health check' route53_health_check: state: absent name: '{{ tiny_prefix }}-{{ item }}-test-hc-delete-if-found' @@ -172,7 +172,7 @@ with_items: - '{{ resource_path }}' - - name: 'Delete multiple HTTP health checks with different resource_path' + - name: 'Delete HTTP health check' route53_health_check: state: absent name: '{{ tiny_prefix }}-{{ item }}-test-hc-delete-if-found' From 5010a6e7eb18e97ef120ed913d6c2964c03a0739 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 8 Nov 2022 10:18:19 -0800 Subject: [PATCH 5/5] Remove redundant if-else block --- plugins/modules/route53_health_check.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/modules/route53_health_check.py b/plugins/modules/route53_health_check.py index 0009b681e2e..7a4dc6f2f4a 100644 --- a/plugins/modules/route53_health_check.py +++ b/plugins/modules/route53_health_check.py @@ -627,10 +627,7 @@ def main(): tags['Name'] = health_check_name else: - if update_delete_by_id: - changed, action, check_id = update_health_check(existing_check) - else: - changed, action, check_id = update_health_check(existing_check) + changed, action, check_id = update_health_check(existing_check) if check_id: changed |= manage_tags(module, client, 'healthcheck', check_id,