Skip to content

Commit

Permalink
ec2_vol: returns an up to date tag dict of the volume (ansible-collec…
Browse files Browse the repository at this point in the history
…tions#241)

This patch ensures a `ec2_vol` calls will return the up to date
tag structure.
Previously, the module was returning the origin tag dictionary.
  • Loading branch information
goneri authored Jan 18, 2021
1 parent cbcec28 commit bec6f91
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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).
8 changes: 5 additions & 3 deletions plugins/modules/ec2_vol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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
Expand Down Expand Up @@ -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'])
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/targets/ec2_vol/tasks/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit bec6f91

Please sign in to comment.