From e5258662eb3abb3746d721b99a2098cfda46d4c7 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 Depends-On: https://github.com/ansible-collections/amazon.aws/pull/241 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 | 5 +++-- tests/integration/targets/ec2_vol/tasks/main.yml | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) 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 9507f35167d..9734614bac7 100644 --- a/plugins/modules/ec2_vol.py +++ b/plugins/modules/ec2_vol.py @@ -707,8 +707,9 @@ def main(): attach_state_changed = False volume, changed = create_volume(module, ec2_conn, zone=zone) - tags['Name'] = name - final_tags, tags_changed = ensure_tags(module, ec2_conn, volume['volume_id'], 'volume', tags, False) + if name: + tags['Name'] = name + final_tags, tags_changed = ensure_tags(module, ec2_conn, volume['volume_id'], 'volume', tags, True) if detach_vol_flag: volume, changed = detach_volume(module, ec2_conn, volume_dict=volume) diff --git a/tests/integration/targets/ec2_vol/tasks/main.yml b/tests/integration/targets/ec2_vol/tasks/main.yml index dddd60fa312..f15195051f4 100644 --- a/tests/integration/targets/ec2_vol/tasks/main.yml +++ b/tests/integration/targets/ec2_vol/tasks/main.yml @@ -78,6 +78,7 @@ - not volume1.volume.attachment_set.instance_id - not volume1.volume.encrypted - volume1.volume.tags.ResourcePrefix == "{{ resource_prefix }}" + - not ("Name" in volume1.volume.tags) # no idempotency check needed here @@ -107,6 +108,7 @@ - volume2.volume.size == 4 - volume2.volume.encrypted - volume2.volume.tags.ResourcePrefix == "{{ resource_prefix }}" + - volume2.volume.tags.Name == "{{ resource_prefix }}" - name: create another volume (override module defaults) (idempotent) ec2_vol: