Skip to content

Commit

Permalink
ec2_vol: returns an up to date tag dict of the volume
Browse files Browse the repository at this point in the history
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 committed Jan 15, 2021
1 parent 3ef1de8 commit 14741d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions plugins/modules/ec2_vol.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,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 @@ -517,7 +519,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 @@ -714,7 +716,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/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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 @@ -105,6 +106,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 14741d2

Please sign in to comment.