diff --git a/changelogs/fragments/1077-s3_lifecycle-transition-days-zero.yml b/changelogs/fragments/1077-s3_lifecycle-transition-days-zero.yml new file mode 100644 index 00000000000..cdef5072d6b --- /dev/null +++ b/changelogs/fragments/1077-s3_lifecycle-transition-days-zero.yml @@ -0,0 +1,2 @@ +bugfixes: + - s3_lifecycle - add support of value *0* for ``transition_days`` (https://github.com/ansible-collections/community.aws/pull/1077). diff --git a/plugins/modules/s3_lifecycle.py b/plugins/modules/s3_lifecycle.py index c12ce6b0897..3f0bd784cef 100644 --- a/plugins/modules/s3_lifecycle.py +++ b/plugins/modules/s3_lifecycle.py @@ -314,7 +314,7 @@ def build_rule(client, module): t_out = dict() if transition.get('transition_date'): t_out['Date'] = transition['transition_date'] - elif transition.get('transition_days'): + elif transition.get('transition_days') is not None: t_out['Days'] = transition['transition_days'] if transition.get('storage_class'): t_out['StorageClass'] = transition['storage_class'].upper() @@ -596,7 +596,7 @@ def main(): 'noncurrent_version_transition_days', 'noncurrent_version_transitions') for param in required_when_present: - if module.params.get(param): + if module.params.get(param) is None: break else: msg = "one of the following is required when 'state' is 'present': %s" % ', '.join(required_when_present) diff --git a/tests/integration/targets/s3_lifecycle/tasks/main.yml b/tests/integration/targets/s3_lifecycle/tasks/main.yml index 566a8381c19..87607f683d8 100644 --- a/tests/integration/targets/s3_lifecycle/tasks/main.yml +++ b/tests/integration/targets/s3_lifecycle/tasks/main.yml @@ -180,6 +180,30 @@ prefix: /something register: output + - assert: + that: + - output is not changed + # ============================================================ + - name: Create a lifecycle policy, with transition_days to 0 + s3_lifecycle: + name: '{{ bucket_name }}' + transition_days: 0 + storage_class: standard_ia + prefix: /something + register: output + + - assert: + that: + - output is changed + # ============================================================ + - name: Create a lifecycle policy, with transition_days to 0 (idempotency) + s3_lifecycle: + name: '{{ bucket_name }}' + transition_days: 0 + storage_class: standard_ia + prefix: /something + register: output + - assert: that: - output is not changed