Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec2_vol: returns an up to date tag dict of the volume #241

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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