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 15, 2021
1 parent 30d8e6b commit e525866
Show file tree
Hide file tree
Showing 3 changed files with 8 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 @@ -707,8 +707,9 @@ def main():

attach_state_changed = False
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
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 @@ -78,6 +78,7 @@
- not volume1.volume.attachment_set.instance_id
- not volume1.volume.encrypted
- volume1.volume.tags.ResourcePrefix == "{{ resource_prefix }}"
- not ("Name" in volume1.volume.tags)

# no idempotency check needed here

Expand Down Expand Up @@ -107,6 +108,7 @@
- volume2.volume.size == 4
- volume2.volume.encrypted
- volume2.volume.tags.ResourcePrefix == "{{ resource_prefix }}"
- volume2.volume.tags.Name == "{{ resource_prefix }}"

- name: create another volume (override module defaults) (idempotent)
ec2_vol:
Expand Down

0 comments on commit e525866

Please sign in to comment.