Skip to content

Commit

Permalink
ec2_vol: preset the name tag of the volume
Browse files Browse the repository at this point in the history
  • Loading branch information
goneri committed Jan 18, 2021
1 parent cbcec28 commit 48d8424
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 3 additions & 2 deletions plugins/modules/ec2_vol.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,9 @@ def main():
else:
volume, changed = create_volume(module, ec2_conn, zone=zone)

tags['Name'] = name
final_tags, tags_changed = ensure_tags(module, ec2_conn, volume['volume_id'], 'volume', tags, False)
if name:
tags['Name'] = name
final_tags, tags_changed = ensure_tags(module, ec2_conn, volume['volume_id'], 'volume', tags, True)

if detach_vol_flag:
volume, changed = detach_volume(module, ec2_conn, volume_dict=volume)
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/targets/ec2_vol/tasks/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

# no idempotency check needed here
Expand Down Expand Up @@ -102,6 +103,7 @@
- volume2.volume_type == 'io1'
- volume2.volume.iops == 101
- volume2.volume.size == 4
- volume2.volume.tags.Name == "{{ resource_prefix }}"
- volume2.volume.encrypted

- name: create another volume (override module defaults) (idempotent)
Expand Down Expand Up @@ -208,6 +210,7 @@
volume_size: 1
volume_type: gp2
tags:
my_tag: foo
ResourcePrefix: "{{ resource_prefix }}"
register: new_vol_attach_result

Expand All @@ -220,6 +223,7 @@
- new_vol_attach_result.volume.attachment_set.status in ['attached', 'attaching']
- new_vol_attach_result.volume.attachment_set.instance_id == test_instance.instance_ids[0]
- new_vol_attach_result.volume.attachment_set.device == '/dev/sdh'
- new_vol_attach_result.volume.tags.my_tag == 'foo'

- name: attach a new volume to an instance (idempotent)
ec2_vol:
Expand Down Expand Up @@ -337,6 +341,8 @@
that:
- changed_gp3_volume.volume_type == 'gp3'
- changed_gp3_volume.changed
# Ensure our tag is still here
- changed_gp3_volume.volume.tags.my_tag == 'foo'

- name: volume must be from type gp3 (idempotent)
ec2_vol:
Expand Down

0 comments on commit 48d8424

Please sign in to comment.