Skip to content

Commit

Permalink
ec2_lc: add volume throughput parameter support (ansible-collections#790
Browse files Browse the repository at this point in the history
)

ec2_lc: add volume throughput parameter support

SUMMARY

Adding throughput parameter support to ec2_lc.
Fixes ansible-collections#784.

ISSUE TYPE


Feature Pull Request

COMPONENT NAME

community.aws.ec2_lc
UPDATE:
Integration tests being added in a separate PR: ansible-collections#824

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Jill R <None>
  • Loading branch information
mandar242 authored Jan 25, 2022
1 parent 9110162 commit dc26f89
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ec2_lc - add support for throughput parameter (https://github.com/ansible-collections/community.aws/pull/790).
13 changes: 12 additions & 1 deletion plugins/modules/ec2_lc.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@
description:
- The number of IOPS per second to provision for the volume.
- Required when I(volume_type=io1).
throughput:
type: int
description:
- The throughput to provision for a gp3 volume.
- Valid Range is a minimum value of 125 and a maximum value of 1000.
version_added: 3.1.0
encrypted:
type: bool
default: false
Expand Down Expand Up @@ -478,7 +484,7 @@ def create_block_device_meta(module, volume):
if 'no_device' in volume:
return_object['NoDevice'] = volume.get('no_device')

if any(key in volume for key in ['snapshot', 'volume_size', 'volume_type', 'delete_on_termination', 'iops', 'encrypted']):
if any(key in volume for key in ['snapshot', 'volume_size', 'volume_type', 'delete_on_termination', 'iops', 'throughput', 'encrypted']):
return_object['Ebs'] = {}

if 'snapshot' in volume:
Expand All @@ -496,6 +502,11 @@ def create_block_device_meta(module, volume):
if 'iops' in volume:
return_object['Ebs']['Iops'] = volume.get('iops')

if 'throughput' in volume:
if volume.get('volume_type') != 'gp3':
module.fail_json(msg='The throughput parameter is supported only for GP3 volumes.')
return_object['Ebs']['Throughput'] = volume.get('throughput')

if 'encrypted' in volume:
return_object['Ebs']['Encrypted'] = volume.get('encrypted')

Expand Down
86 changes: 85 additions & 1 deletion tests/integration/targets/ec2_lc/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,58 @@
- lc_2_create_idem is not changed
- '"autoscaling:CreateLaunchConfiguration" not in lc_2_create_idem.resource_actions'

- name: Create launch configuration 3 - test throughput parameter
vars:
ansible_python_interpreter: "{{ botocore_virtualenv_interpreter }}"
community.aws.ec2_lc:
name: '{{ resource_prefix }}-lc3'
image_id: '{{ ec2_ami_id }}'
instance_type: '{{ ec2_instance_type }}'
volumes:
- device_name: /dev/sda1
volume_size: 10
volume_type: gp3
throughput: 250
delete_on_termination: true
register: lc_3_create

- name: Gather information about launch configuration 3
vars:
ansible_python_interpreter: "{{ botocore_virtualenv_interpreter }}"
community.aws.ec2_lc_info:
name: '{{ resource_prefix }}-lc3'
register: lc_3_info_result

- assert:
that:
- lc_3_create is changed
- '"throughput" in lc_3_info_result.launch_configurations[0].block_device_mappings[0].ebs'
- lc_3_info_result.launch_configurations[0].block_device_mappings[0].ebs.throughput == 250
- lc_3_info_result.launch_configurations[0].block_device_mappings[0].ebs.volume_size == 10
- lc_3_info_result.launch_configurations[0].block_device_mappings[0].ebs.volume_type == 'gp3'
- lc_3_info_result.launch_configurations[0].instance_type == 't2.micro'
- '"autoscaling:CreateLaunchConfiguration" in lc_3_create.resource_actions'

- name: Create launch configuration 3 - Idempotency
vars:
ansible_python_interpreter: "{{ botocore_virtualenv_interpreter }}"
community.aws.ec2_lc:
name: '{{ resource_prefix }}-lc3'
image_id: '{{ ec2_ami_id }}'
instance_type: '{{ ec2_instance_type }}'
volumes:
- device_name: /dev/sda1
volume_size: 10
volume_type: gp3
throughput: 250
delete_on_termination: true
register: lc_3_create_idem

- assert:
that:
- lc_3_create_idem is not changed
- '"autoscaling:CreateLaunchConfiguration" not in lc_3_create_idem.resource_actions'

- name: Search for the Launch Configurations that start with test resource_prefix
community.aws.ec2_lc_find:
name_regex: '{{ resource_prefix }}*'
Expand All @@ -120,7 +172,7 @@

- assert:
that:
- lc_find_result.results | length == 2
- lc_find_result.results | length == 3
- '"autoscaling:DescribeLaunchConfigurations" in lc_find_result.resource_actions'

- name: Delete launch configuration 1
Expand Down Expand Up @@ -187,6 +239,38 @@
- lc_2_info_result is not changed
- lc_2_info_result.launch_configurations | length == 0

- name: Delete launch configuration 3
community.aws.ec2_lc:
name: '{{ resource_prefix }}-lc3'
state: absent
register: lc_3_delete

- assert:
that:
- lc_3_delete is changed
- '"autoscaling:DeleteLaunchConfiguration" in lc_3_delete.resource_actions'

- name: Delete launch configuration 3 - Idempotency
community.aws.ec2_lc:
name: '{{ resource_prefix }}-lc3'
state: absent
register: lc_3_delete_idem

- assert:
that:
- lc_3_delete_idem is not changed
- '"autoscaling:DeleteLaunchConfiguration" not in lc_3_delete_idem.resource_actions'

- name: Gather information about launch configuration 3
community.aws.ec2_lc_info:
name: '{{ resource_prefix }}-lc2'
register: lc_3_info_result

- assert:
that:
- lc_3_info_result is not changed
- lc_3_info_result.launch_configurations | length == 0

always:

- include_tasks: env_cleanup.yml

0 comments on commit dc26f89

Please sign in to comment.