diff --git a/changelogs/fragments/241_ec2_vol-returns-an-up-to-date-tag-dict-of-the-volume.yaml b/changelogs/fragments/241_ec2_vol-returns-an-up-to-date-tag-dict-of-the-volume.yaml new file mode 100644 index 00000000000..8b9fa4750f3 --- /dev/null +++ b/changelogs/fragments/241_ec2_vol-returns-an-up-to-date-tag-dict-of-the-volume.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- ec2_vol - a creation or update now returns a structure with an up to date list of tags (https://github.com/ansible-collections/amazon.aws/pull/241). diff --git a/plugins/modules/ec2_vol.py b/plugins/modules/ec2_vol.py index 794e72a5299..fb85a85dcc3 100644 --- a/plugins/modules/ec2_vol.py +++ b/plugins/modules/ec2_vol.py @@ -569,7 +569,9 @@ def detach_volume(module, ec2_conn, volume_dict): return volume_dict, changed -def get_volume_info(volume): +def get_volume_info(volume, tags=None): + if not tags: + tags = boto3_tag_list_to_ansible_dict(volume.get('tags')) attachment_data = get_attachment_data(volume) volume_info = { 'create_time': volume.get('create_time'), @@ -589,7 +591,7 @@ def get_volume_info(volume): 'status': attachment_data.get('state', None), 'deleteOnTermination': attachment_data.get('delete_on_termination', None) }, - 'tags': boto3_tag_list_to_ansible_dict(volume.get('tags')) + 'tags': tags } return volume_info @@ -790,7 +792,7 @@ def main(): volume, changed = attach_volume(module, ec2_conn, volume_dict=volume, instance_dict=inst, device_name=device_name) # Add device, volume_id and volume_type parameters separately to maintain backward compatibility - volume_info = get_volume_info(volume) + volume_info = get_volume_info(volume, tags=final_tags) module.exit_json(changed=changed, volume=volume_info, device=volume_info['attachment_set']['device'], volume_id=volume_info['id'], volume_type=volume_info['type']) diff --git a/tests/integration/targets/ec2_vol/tasks/tests.yml b/tests/integration/targets/ec2_vol/tasks/tests.yml index d7d5bf3c684..42cd8de3f7c 100644 --- a/tests/integration/targets/ec2_vol/tasks/tests.yml +++ b/tests/integration/targets/ec2_vol/tasks/tests.yml @@ -75,6 +75,7 @@ - "'instance_id' in volume1.volume.attachment_set" - not volume1.volume.attachment_set.instance_id - not volume1.volume.encrypted + - volume1.volume.tags.ResourcePrefix == "{{ resource_prefix }}" # no idempotency check needed here @@ -103,6 +104,7 @@ - volume2.volume.iops == 101 - volume2.volume.size == 4 - volume2.volume.encrypted + - volume2.volume.tags.ResourcePrefix == "{{ resource_prefix }}" - name: create another volume (override module defaults) (idempotent) ec2_vol: