Skip to content

Commit

Permalink
ec2_instance - Support throughtput parameter for GP3 volume types (an…
Browse files Browse the repository at this point in the history
…sible-collections#433)

ec2_instance -  Support throughtput parameter for GP3 volume types

SUMMARY

ec2_instance - Support throughput parameter for GP3 volume types
Fixes ansible-collections#395
ISSUE TYPE


Feature Pull Request

COMPONENT NAME

ec2_instance

Reviewed-by: Markus Bergholz <[email protected]>
Reviewed-by: Mark Chappell <None>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: Jill R <None>
Reviewed-by: None <None>
  • Loading branch information
alinabuzachis authored Aug 25, 2021
1 parent 19ea763 commit cc94310
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/433-ec2_instance-throughput.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ec2_instance - add ``throughput`` parameter for gp3 volume types (https://github.com/ansible-collections/amazon.aws/pull/433).
10 changes: 10 additions & 0 deletions plugins/modules/ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit cc94310

Please sign in to comment.