Repository: ansible-collections/amazon.aws

Issue:
route53_health_check - no "health_check" information returned when updating 
### Summary

When updating a Route53 health check the only information returned is that it was changed

One suggestion is to update `update_health_check` so it returns `check_id` in all 3 spots (need to move `check_id = existing_check.get('Id')` further up in the method)
https://github.com/ansible-collections/amazon.aws/blob/f9751fab28c55d793df7996f599839a3ace5414b/plugins/modules/route53_health_check.py#L472

Only happens when the following snippet doesn't find an existing health check
https://github.com/ansible-collections/amazon.aws/blob/f9751fab28c55d793df7996f599839a3ace5414b/plugins/modules/route53_health_check.py#L592

### Issue Type

Bug Report

### Component Name

route53_health_check

### Ansible Version

```console (paste below)
$ ansible --version

ansible [core 2.12.2]
  config file = /Users/<USER>/Source/dataintelligence-ansible/ansible.cfg
  configured module search path = ['/Users/<USER>/Source/dataintelligence-ansible/library']
  ansible python module location = /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/<USER>/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/bin/ansible
  python version = 3.9.8 (main, Nov 18 2021, 16:08:04) [Clang 12.0.5 (clang-1205.0.22.9)]
  jinja version = 2.11.3
  libyaml = True
```


### Collection Versions

Manually added https://github.com/ansible-collections/amazon.aws/blob/5.0.2/plugins/modules/route53_health_check.py to my local Ansible

### AWS SDK versions

```console (paste below)
$ pip show boto boto3 botocore

Name: boto
Version: 2.49.0
Summary: Amazon Web Services Library
Home-page: https://github.com/boto/boto/
Author: Mitch Garnaat
Author-email: mitch@garnaat.com
License: MIT
Location: /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages
Requires:
Required-by:
---
Name: boto3
Version: 1.20.48
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email:
License: Apache License 2.0
Location: /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages
Requires: botocore, jmespath, s3transfer
Required-by: aws-sam-cli, aws-sam-translator, serverlessrepo
---
Name: botocore
Version: 1.23.48
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email:
License: Apache License 2.0
Location: /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages
Requires: jmespath, python-dateutil, urllib3
Required-by: awscli, boto3, s3transfer
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed

```


### OS / Environment

macOS 11.6

### Steps to Reproduce

Run the following playbook twice (change `fqdn` to a new value before the 2nd run)

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- hosts: localhost
  tasks:
    - name: Create a health-check
      route53_health_check:
        health_check_name: my-health-check
        use_unique_names: true
        fqdn: ***
        type: HTTPS
        resource_path: /
        request_interval: 30
        failure_threshold: 3
        tags:
          Service: my-service
          Owner: some-owner
          Lifecycle: dev
      register: my_health_check
```


### Expected Results

#### First Run (create)

```yaml (paste below)
changed: [localhost] => changed=true
  health_check:
    action: create
    caller_reference: ***
    health_check_config:
      ...
```

#### Second Run (update)

```yaml (paste below)
changed: [localhost] => changed=true
  health_check:
    action: update
    caller_reference: ***
    health_check_config:
      ...
```

### Actual Results

#### First Run (create)

```yaml (paste below)
changed: [localhost] => changed=true
  health_check:
    action: create
    caller_reference: ***
    health_check_config:
      ...
```

#### Second Run (update, no `health_check_config` returned)

```yaml (paste below)
changed: [localhost] => changed=true
  health_check:
    action: update
```

### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/route53_health_check.py`](https://github.com/['ansible-collections/amazon.aws', 'ansible-collections/community.aws', 'ansible-collections/community.vmware']/blob/main/plugins/modules/route53_health_check.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @jillr @s-hertel @tremble @zimbatm
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/route53_health_check.py b/plugins/modules/route53_health_check.py
--- 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)
@@ -627,10 +627,7 @@ def main():
                         tags['Name'] = health_check_name
 
             else:
-                if update_delete_by_id:
-                    changed, action = 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,


Test patch:
diff --git a/tests/integration/targets/route53_health_check/defaults/main.yml b/tests/integration/targets/route53_health_check/defaults/main.yml
--- 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
--- 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,18 +117,70 @@
         - '"route53:UpdateHealthCheck" not in create_idem.results[0].resource_actions'
         - '"route53:UpdateHealthCheck" not in create_idem.results[1].resource_actions'
 
+    - name: 'Update HTTP health check - update port'
+      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 - update port'
+      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'
+      - name: 'Delete HTTP health check'
         route53_health_check:
           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 HTTP health check'
+        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 }}'