From cc94310020fb68489878589e8b8aa0f1b3c37404 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Wed, 25 Aug 2021 20:59:07 +0200 Subject: [PATCH] ec2_instance - Support throughtput parameter for GP3 volume types (#433) ec2_instance - Support throughtput parameter for GP3 volume types SUMMARY ec2_instance - Support throughput parameter for GP3 volume types Fixes #395 ISSUE TYPE Feature Pull Request COMPONENT NAME ec2_instance Reviewed-by: Markus Bergholz Reviewed-by: Mark Chappell Reviewed-by: Alina Buzachis Reviewed-by: Jill R Reviewed-by: None --- .../fragments/433-ec2_instance-throughput.yml | 2 ++ plugins/modules/ec2_instance.py | 10 +++++++ .../ec2_instance/tasks/block_devices.yml | 28 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 changelogs/fragments/433-ec2_instance-throughput.yml diff --git a/changelogs/fragments/433-ec2_instance-throughput.yml b/changelogs/fragments/433-ec2_instance-throughput.yml new file mode 100644 index 00000000000..620cbec222d --- /dev/null +++ b/changelogs/fragments/433-ec2_instance-throughput.yml @@ -0,0 +1,2 @@ +minor_changes: + - ec2_instance - add ``throughput`` parameter for gp3 volume types (https://github.com/ansible-collections/amazon.aws/pull/433). \ No newline at end of file diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index 984b4dbc44e..d81312279f8 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -179,6 +179,7 @@ - A list of block device mappings, by default this will always use the AMI root device so the volumes option is primarily for adding more storage. - A mapping contains the (optional) keys device_name, virtual_name, ebs.volume_type, ebs.volume_size, ebs.kms_key_id, ebs.iops, and ebs.delete_on_termination. + - Set ebs.throughput value requires botocore>=1.19.27. - For more information about each parameter, see U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_BlockDeviceMapping.html). type: list elements: dict @@ -954,6 +955,15 @@ def build_volume_spec(params): for int_value in ['volume_size', 'iops']: if int_value in volume['ebs']: volume['ebs'][int_value] = int(volume['ebs'][int_value]) + if 'volume_type' in volume['ebs'] and volume['ebs']['volume_type'] == 'gp3': + if not volume['ebs'].get('iops'): + volume['ebs']['iops'] = 3000 + if 'throughput' in volume['ebs']: + module.require_botocore_at_least('1.19.27', reason='to set throughtput value') + volume['ebs']['throughput'] = int(volume['ebs']['throughput']) + else: + volume['ebs']['throughput'] = 125 + return [snake_dict_to_camel_dict(v, capitalize_first=True) for v in volumes] diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml index 0a8ab63f08b..0a0ac2a95f1 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml +++ b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml @@ -71,6 +71,34 @@ ec2_instance: state: absent instance_ids: "{{ block_device_instances.instance_ids }}" + + - name: "New instance with an extra block device - gp3 volume_type and throughput" + ec2_instance: + state: present + name: "{{ resource_prefix }}-test-ebs-vols-gp3" + image_id: "{{ ec2_ami_image }}" + vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" + volumes: + - device_name: /dev/sdb + ebs: + volume_size: 20 + delete_on_termination: true + volume_type: gp3 + throughput: 500 + tags: + TestId: "{{ ec2_instance_tag_TestId }}" + instance_type: "{{ ec2_instance_type }}" + wait: true + register: block_device_instances_gp3 + + - assert: + that: + - block_device_instances_gp3 is not failed + - block_device_instances_gp3 is changed + - block_device_instances_gp3.spec.BlockDeviceMappings[0].DeviceName == '/dev/sdb' + - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.VolumeType == 'gp3' + - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.VolumeSize == 20 + - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.Throughput == 500 always: - name: "Terminate block_devices instances"