Repository: ansible-collections/community.aws

Issue:
cloudfront_distribution.py - wait_until_processed appears broken
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
<!--- Explain the problem briefly below -->
A cloudfront_distribution which performs its operation and the cloudfront distribution is created successfully. However, when `wait: yes` is enabled the error is detailed below.

Digging around the source I've been unable to find anything on my own where the key error could be originating from.
This behavior only occurs on creation with `state: present`, not on deletion with `state: absent`

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
cloudfront_distribution

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
13:18 $ ansible --version
ansible 2.10.1
  config file = /Users/redacted/redacted/ansible-roles/ansible.role-cloudfront-stream-distribution/ansible.cfg
  configured module search path = ['/Users/redacted/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.7.7 (default, Mar 10 2020, 15:43:27) [Clang 10.0.0 (clang-1000.11.45.5)]
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below
13:43 $ ansible-config dump --only-changed
INTERPRETER_PYTHON(/Users/redacted/redacted/ansible-roles/ansible.role-cloudfront-stream-distribution/ansible.cfg) = auto
(END)
```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
```
Darwin 17.7.0 Darwin Kernel Version 17.7.0: Wed Apr 24 21:17:24 PDT 2019; root:xnu-4570.71.45~1/RELEASE_X86_64 x86_64
MacOS 10.13.6
```

##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->
I haven't been able to fully deconstruct it yet to a minimal case, I will try to update with one if I can. Right now I can reproduce by using `wait: yes`, and it goes away with `wait: no`

<!--- Paste example playbooks or commands between quotes below -->
```yaml

```

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
The ansible routine to wait until the distribution is made and reports healthy and then exit with my registered variable populated.

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes -->
```paste below
TASK [/Users/redacted/redacted/ansible-roles/ansible.role-cloudfront-stream-distribution : Create / Manage / Delete distribution (This may take some time)] ***
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'Id'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/Users/redacted/.ansible/tmp/ansible-tmp-1602015472.329021-59538-203288307626216/AnsiballZ_cloudfront_distribution.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/Users/redacted/.ansible/tmp/ansible-tmp-1602015472.329021-59538-203288307626216/AnsiballZ_cloudfront_distribution.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/redacted/.ansible/tmp/ansible-tmp-1602015472.329021-59538-203288307626216/AnsiballZ_cloudfront_distribution.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.cloudfront_distribution', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/var/folders/w_/1n5tpdtx3h1f5k3skn3d6d9r0000gn/T/ansible_community.aws.cloudfront_distribution_payload_lk_w9xob/ansible_community.aws.cloudfront_distribution_payload.zip/ansible_collections/community/aws/plugins/modules/cloudfront_distribution.py\", line 2252, in <module>\n  File \"/var/folders/w_/1n5tpdtx3h1f5k3skn3d6d9r0000gn/T/ansible_community.aws.cloudfront_distribution_payload_lk_w9xob/ansible_community.aws.cloudfront_distribution_payload.zip/ansible_collections/community/aws/plugins/modules/cloudfront_distribution.py\", line 2242, in main\n  File \"/var/folders/w_/1n5tpdtx3h1f5k3skn3d6d9r0000gn/T/ansible_community.aws.cloudfront_distribution_payload_lk_w9xob/ansible_community.aws.cloudfront_distribution_payload.zip/ansible_collections/community/aws/plugins/modules/cloudfront_distribution.py\", line 2072, in wait_until_processed\nKeyError: 'Id'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
```



Discussion:
Files identified in the description:
* [`plugins/modules/cloudfront_distribution.py`](https://github.com/ansible-collections/community.aws/blob/main/plugins/modules/cloudfront_distribution.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 @willthames @wilvk @wimnat
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/cloudfront_distribution.py b/plugins/modules/cloudfront_distribution.py
--- a/plugins/modules/cloudfront_distribution.py
+++ b/plugins/modules/cloudfront_distribution.py
@@ -2316,7 +2316,8 @@ def validate_distribution_id_from_alias(self, aliases):
 
     def wait_until_processed(self, client, wait_timeout, distribution_id, caller_reference):
         if distribution_id is None:
-            distribution_id = self.validate_distribution_from_caller_reference(caller_reference=caller_reference)["Id"]
+            distribution = self.validate_distribution_from_caller_reference(caller_reference=caller_reference)
+            distribution_id = distribution["Distribution"]["Id"]
 
         try:
             waiter = client.get_waiter("distribution_deployed")


Test patch: