From 37eae0e8c8405dbbd368ba79fc7a38068fd4560a Mon Sep 17 00:00:00 2001 From: Brian Scholer <1260690+briantist@users.noreply.github.com> Date: Wed, 26 Jan 2022 16:52:09 -0500 Subject: [PATCH] `ec2_vol` - support changing from volume without IOPS to one with IOPS (#627) `ec2_vol` - support changing from volume without IOPS to one with IOPS SUMMARY Fixes #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: Markus Bergholz Reviewed-by: Alina Buzachis Reviewed-by: None (cherry picked from commit a9b9bd13f412b9ff2a6a2fa1be5ecce08cfc2d0b) --- ...626-ec2_vol-iops-when-source-does-not-have-iops.yml | 3 +++ plugins/modules/ec2_vol.py | 4 ++-- tests/integration/targets/ec2_vol/tasks/main.yml | 10 +++++----- 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/626-ec2_vol-iops-when-source-does-not-have-iops.yml diff --git a/changelogs/fragments/626-ec2_vol-iops-when-source-does-not-have-iops.yml b/changelogs/fragments/626-ec2_vol-iops-when-source-does-not-have-iops.yml new file mode 100644 index 00000000000..6c518b6b932 --- /dev/null +++ b/changelogs/fragments/626-ec2_vol-iops-when-source-does-not-have-iops.yml @@ -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). diff --git a/plugins/modules/ec2_vol.py b/plugins/modules/ec2_vol.py index 03f7d3e29cc..30b685c88d4 100644 --- a/plugins/modules/ec2_vol.py +++ b/plugins/modules/ec2_vol.py @@ -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 @@ -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 diff --git a/tests/integration/targets/ec2_vol/tasks/main.yml b/tests/integration/targets/ec2_vol/tasks/main.yml index 0ebd39c5af4..d4add04cb43 100644 --- a/tests/integration/targets/ec2_vol/tasks/main.yml +++ b/tests/integration/targets/ec2_vol/tasks/main.yml @@ -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' @@ -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 @@ -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 @@ -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 ❤️' @@ -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 ❤️'