Repository: ansible/ansible

Issue:
cloudwatchlogs_log_group won't change retention policy
<!---
Verify first that your issue/request is not already reported on GitHub.
THIS FORM WILL BE READ BY A MACHINE, COMPLETE ALL SECTIONS AS DESCRIBED.
Also test if the latest release, and devel branch are affected too.
ALWAYS add information AFTER (OUTSIDE) these html comments.
Otherwise it may end up being automatically closed by our bot. -->

##### SUMMARY
<!--- Explain the problem briefly -->
cloudwatchlogs_log_group returns unchanged when trying to change log retention policy
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
<!--- Insert, BELOW THIS COMMENT, the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path-->
cloudwatchlogs_log_group

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.5.5
  config file = /Users/drue/wa/ansible/ansible.cfg
  configured module search path = [u'/Users/drue/wa/ansible/library']
  ansible python module location = /Users/drue/wa/ENV/lib/python2.7/site-packages/ansible
  executable location = /Users/drue/wa/ENV/bin/ansible
  python version = 2.7.15 (default, Jun 16 2018, 10:23:57) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]

```

##### CONFIGURATION
<!--- If using Ansible 2.4 or above, paste, BELOW THIS COMMENT, the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).-->
ANSIBLE_PIPELINING(/Users/drue/wa/ansible/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/Users/drue/wa/ansible/ansible.cfg) = -o ForwardAgent=no -o ControlMaster=auto -o ControlPersist=60s
ANSIBLE_SSH_CONTROL_PATH(/Users/drue/wa/ansible/ansible.cfg) = %(directory)s/%%h-%%r
DEFAULT_MODULE_PATH(/Users/drue/wa/ansible/ansible.cfg) = [u'/Users/drue/wa/SG/ansible/library']
DEFAULT_ROLES_PATH(/Users/drue/wa/ansible/ansible.cfg) = [u'/Users/drue/wa/SG/ansible/roles']
HOST_KEY_CHECKING(/Users/drue/wa/ansible/ansible.cfg) = False

##### OS / ENVIRONMENT
<!--- Mention, BELOW THIS COMMENT, the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.-->
N/A
##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->
create a log group with default retention (unlimited), run a task like example below

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- cloudwatchlogs_log_group:
    state: present
    region: us-east-1
    log_group_name: /aws/lambda/my_lambda
    retention: 30
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
expected the log retention on the log group to change
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
ansible module just returned unchanged, note lack of log retention in return value
<!--- Paste verbatim command output between quotes below -->
```
ok: [local] => {"arn": "arn:aws:logs:us-east-1:320353726149:log-group:/aws/lambda/my_lambda:*", "changed": false, "creation_time": 1529699319022, "log_group_name": "/aws/lambda/my_lambda", "metric_filter_count": 0, "stored_bytes": 0}
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/cloud/amazon/cloudwatchlogs_log_group.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/amazon/cloudwatchlogs_log_group.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 @willricardo
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/cloudwatchlogs_log_group.py b/lib/ansible/modules/cloud/amazon/cloudwatchlogs_log_group.py
--- a/lib/ansible/modules/cloud/amazon/cloudwatchlogs_log_group.py
+++ b/lib/ansible/modules/cloud/amazon/cloudwatchlogs_log_group.py
@@ -257,6 +257,14 @@ def main():
                                                tags=module.params['tags'],
                                                retention=module.params['retention'],
                                                module=module)
+        elif found_log_group:
+            if module.params['retention'] != found_log_group['retentionInDays']:
+                changed = True
+                input_retention_policy(client=logs,
+                                       log_group_name=module.params['log_group_name'],
+                                       retention=module.params['retention'],
+                                       module=module)
+                found_log_group['retentionInDays'] = module.params['retention']
 
         module.exit_json(changed=changed, **camel_dict_to_snake_dict(found_log_group))
 


Test patch: