Skip to content

Commit

Permalink
ec2_instance - Support throughtput parameter for GP3 volume types
Browse files Browse the repository at this point in the history
Signed-off-by: Alina Buzachis <[email protected]>
  • Loading branch information
alinabuzachis committed Aug 3, 2021
1 parent 469dde5 commit 69b18e9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugins/modules/ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,12 @@ 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']:
volume['ebs']['throughput'] = int(volume['ebs']['throughput'])

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,44 @@
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

- name: "Gather instance info"
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-test-ebs-vols-gp3"
register: block_device_instances_gp3_info

- assert:
that:
- block_device_instances_gp3 is not failed
- block_device_instances_gp3 is changed
- block_device_instances_gp3_info.instances[0].block_device_mappings[0]
- block_device_instances_gp3_info.instances[0].block_device_mappings[1]
- block_device_instances_gp3_info.instances[0].block_device_mappings[1].device_name == '/dev/sdb'

- name: "Terminate instances"
ec2_instance:
state: absent
instance_ids: "{{ block_device_instances_gp3.instance_ids }}"

always:
- name: "Terminate block_devices instances"
Expand Down

0 comments on commit 69b18e9

Please sign in to comment.