From 405d4509650a53ebae3029bb23f2f57f06e1d93c 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 | 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 fb85a85dcc3..28196fae1fb 100644 --- a/plugins/modules/ec2_vol.py +++ b/plugins/modules/ec2_vol.py @@ -783,7 +783,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 42cd8de3f7c..6a770d07a00 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 - volume1.volume.tags.ResourcePrefix == "{{ resource_prefix }}" @@ -103,6 +104,7 @@ - volume2.volume_type == 'io1' - volume2.volume.iops == 101 - volume2.volume.size == 4 + - volume2.volume.tags.Name == "{{ resource_prefix }}" - volume2.volume.encrypted - volume2.volume.tags.ResourcePrefix == "{{ resource_prefix }}"