Skip to content

Commit

Permalink
ec2_vol - support changing from volume without IOPS to one with IOPS (
Browse files Browse the repository at this point in the history
ansible-collections#627) (ansible-collections#640)

[PR ansible-collections#627/a9b9bd13 backport][stable-2] `ec2_vol` - support changing from volume without IOPS to one with IOPS

This is a backport of PR ansible-collections#627 as merged into main (a9b9bd1).
SUMMARY

Fixes ansible-collections#626
Changing from standard volume type to gp3 failed when the module was trying to read the "original" IOPS value from the existing volume, since it doesn't have one.
See the linked issue for detailed description.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_vol
ADDITIONAL INFORMATION



N/A

Reviewed-by: Jill R <None>
  • Loading branch information
patchback[bot] authored Feb 9, 2022
1 parent 63003a5 commit cad363f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- ec2_vol - changing a volume from a type that does not support IOPS (like ``standard``) to a type that does (like ``gp3``) fails (https://github.com/ansible-collections/amazon.aws/issues/626).
4 changes: 2 additions & 2 deletions plugins/modules/ec2_vol.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ def update_volume(module, ec2_conn, volume):

iops_changed = False
target_iops = module.params.get('iops')
original_iops = volume.get('iops')
if target_iops:
original_iops = volume['iops']
if target_iops != original_iops:
iops_changed = True
req_obj['Iops'] = target_iops
Expand All @@ -392,7 +392,7 @@ def update_volume(module, ec2_conn, volume):
# otherwise, the default iops value is applied.
if type_changed and target_type == 'gp3':
if (
(volume['iops'] and (int(volume['iops']) < 3000 or int(volume['iops']) > 16000)) or not volume['iops']
(original_iops and (int(original_iops) < 3000 or int(original_iops) > 16000)) or not original_iops
):
req_obj['Iops'] = 3000
iops_changed = True
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/targets/ec2_vol/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
instance: "{{ test_instance.instance_ids[0] }}"
device_name: /dev/sdh
volume_size: 1
volume_type: gp2
volume_type: standard
name: '{{ resource_prefix }} - sdh'
tags:
"lowercase spaced": 'hello cruel world'
Expand Down Expand Up @@ -316,7 +316,7 @@
instance: "{{ test_instance.instance_ids[0] }}"
device_name: /dev/sdh
volume_size: 1
volume_type: gp2
volume_type: standard
tags:
ResourcePrefix: "{{ resource_prefix }}"
check_mode: true
Expand All @@ -332,7 +332,7 @@
instance: "{{ test_instance.instance_ids[0] }}"
device_name: /dev/sdh
volume_size: 1
volume_type: gp2
volume_type: standard
tags:
ResourcePrefix: "{{ resource_prefix }}"
register: new_vol_attach_result_idem
Expand All @@ -350,7 +350,7 @@
id: "{{ new_vol_attach_result.volume.id }}"
device_name: /dev/sdh
volume_size: 1
volume_type: gp2
volume_type: standard
tags:
"lowercase spaced": 'hello cruel world ❤️'
"Title Case": 'Hello Cruel World ❤️'
Expand All @@ -370,7 +370,7 @@
- "'size' in new_vol_attach_result.volume"
- new_vol_attach_result.volume.size == 1
- "'volume_type' in new_vol_attach_result"
- new_vol_attach_result.volume_type == 'gp2'
- new_vol_attach_result.volume_type == 'standard'
- "'tags' in new_vol_attach_result.volume"
- (new_vol_attach_result.volume.tags | length) == 6
- new_vol_attach_result.volume.tags["lowercase spaced"] == 'hello cruel world ❤️'
Expand Down

0 comments on commit cad363f

Please sign in to comment.