From 559c5cd47d290629f18191374a7e6fd38d5f1749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Fri, 15 Jan 2021 13:10:01 -0500 Subject: [PATCH] ec2_vol: preset the name tag of the volume Closes: https://github.com/ansible-collections/amazon.aws/issues/229 --- .../242_ec2_vol-preset-the-name-tag-of-the-volume.yaml | 3 +++ plugins/modules/ec2_vol.py | 3 ++- tests/integration/targets/ec2_vol/tasks/tests.yml | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/242_ec2_vol-preset-the-name-tag-of-the-volume.yaml diff --git a/changelogs/fragments/242_ec2_vol-preset-the-name-tag-of-the-volume.yaml b/changelogs/fragments/242_ec2_vol-preset-the-name-tag-of-the-volume.yaml new file mode 100644 index 00000000000..efb2a72e676 --- /dev/null +++ b/changelogs/fragments/242_ec2_vol-preset-the-name-tag-of-the-volume.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- ec2_vol - create or update now preserves the existing tags, including Name (https://github.com/ansible-collections/amazon.aws/issues/229) diff --git a/plugins/modules/ec2_vol.py b/plugins/modules/ec2_vol.py index 794e72a5299..ecedf0b28d6 100644 --- a/plugins/modules/ec2_vol.py +++ b/plugins/modules/ec2_vol.py @@ -781,7 +781,8 @@ def main(): else: volume, changed = create_volume(module, ec2_conn, zone=zone) - tags['Name'] = name + if name: + tags['Name'] = name final_tags, tags_changed = ensure_tags(module, ec2_conn, volume['volume_id'], 'volume', tags, False) if detach_vol_flag: diff --git a/tests/integration/targets/ec2_vol/tasks/tests.yml b/tests/integration/targets/ec2_vol/tasks/tests.yml index d7d5bf3c684..59b8ef27ef5 100644 --- a/tests/integration/targets/ec2_vol/tasks/tests.yml +++ b/tests/integration/targets/ec2_vol/tasks/tests.yml @@ -74,6 +74,7 @@ - "'attachment_set' in volume1.volume" - "'instance_id' in volume1.volume.attachment_set" - not volume1.volume.attachment_set.instance_id + - not ("Name" in volume1.volume.tags) - not volume1.volume.encrypted # no idempotency check needed here @@ -102,6 +103,7 @@ - volume2.volume_type == 'io1' - volume2.volume.iops == 101 - volume2.volume.size == 4 + - volume2.volume.tags.Name == "{{ resource_prefix }}" - volume2.volume.encrypted - name: create another volume (override module defaults) (idempotent)