Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rds_instance: support for gp3 #1266

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/1266-rds_instance_gp3_support.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- "rds_instance - add support for gp3 storage type (https://github.com/ansible-collections/amazon.aws/pull/1266)."
45 changes: 44 additions & 1 deletion plugins/modules/rds_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,17 @@
choices:
- standard
- gp2
- gp3
- io1
type: str
storage_throughput:
description:
- The storage throughput when the I(storage_type) is C(gp3).
- When the allocated storage is below 400 GB, the storage throughput will always be 125 mb/s.
- When the allocated storage is large than or equal 400 GB, the througput starts at 500 mb/s.
- Requires boto3 >= 1.26.0.
type: int
version_added: 5.2.0
tde_credential_arn:
description:
- The ARN from the key store with which to associate the instance for Transparent Data Encryption. This is
Expand Down Expand Up @@ -1000,6 +1009,39 @@ def get_options_with_changing_values(client, module, parameters):
parameters['AllocatedStorage'] = new_allocated_storage
parameters['Iops'] = new_iops

if instance.get('StorageType') == 'gp3':
if module.boto3_at_least('1.26.0'):
GP3_THROUGHPUT = True
current_storage_throughput = instance.get('PendingModifiedValues', {}).get('StorageThroughput', instance['StorageThroughput'])
new_storage_throughput = module.params.get('storage_throughput') or current_storage_throughput
if new_storage_throughput != current_storage_throughput:
parameters['StorageThroughput'] = new_storage_throughput
else:
GP3_THROUGHPUT = False
module.warn('gp3 volumes require boto3 >= 1.26.0. storage_throughput will be ignored.')

current_iops = instance.get('PendingModifiedValues', {}).get('Iops', instance['Iops'])
# when you just change from gp2 to gp3, you may not add the iops parameter
new_iops = module.params.get('iops') or current_iops

new_allocated_storage = module.params.get('allocated_storage')
current_allocated_storage = instance.get('PendingModifiedValues', {}).get('AllocatedStorage', instance['AllocatedStorage'])

if current_allocated_storage != new_allocated_storage:
parameters['AllocatedStorage'] = new_allocated_storage

if new_allocated_storage >= 400:
if new_iops < 12000:
module.fail_json(msg='IOPS must be at least 12000 when the allocated storage is larger than or equal to 400 GB.')

if new_storage_throughput < 500 and GP3_THROUGHPUT:
module.fail_json(msg='Storage Throughput must be at least 500 when the allocated storage is larger than or equal to 400 GB.')

if current_iops != new_iops:
parameters['Iops'] = new_iops
# must be always specified when changing iops
parameters['AllocatedStorage'] = new_allocated_storage

if parameters.get('NewDBInstanceIdentifier') and instance.get('PendingModifiedValues', {}).get('DBInstanceIdentifier'):
if parameters['NewDBInstanceIdentifier'] == instance['PendingModifiedValues']['DBInstanceIdentifier'] and not apply_immediately:
parameters.pop('NewDBInstanceIdentifier')
Expand Down Expand Up @@ -1311,7 +1353,8 @@ def main():
source_engine_version=dict(),
source_region=dict(),
storage_encrypted=dict(type='bool'),
storage_type=dict(choices=['standard', 'gp2', 'io1']),
storage_type=dict(choices=['standard', 'gp2', 'gp3', 'io1']),
storage_throughput=dict(type='int'),
tags=dict(type='dict', aliases=['resource_tags']),
tde_credential_arn=dict(aliases=['transparent_data_encryption_arn']),
tde_credential_password=dict(no_log=True, aliases=['transparent_data_encryption_password']),
Expand Down
56 changes: 56 additions & 0 deletions tests/integration/targets/rds_instance_modify/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,62 @@
# monitoring_role_arn, monitoring_interval, domain, domain_iam_role_name, cloudwatch_logs_export_configuration

# ------------------------------------------------------------------------------------------
- name: Modify the storage type without immediate application - check_mode
rds_instance:
id: '{{ instance_id }}'
state: present
storage_type: gp3
apply_immediately: false
register: result
check_mode: yes

- assert:
that:
- result.changed
- 'result.storage_type == "gp2"'

- name: Modify the storage type without immediate application
rds_instance:
id: '{{ instance_id }}'
state: present
storage_type: gp3
apply_immediately: false
register: result

- assert:
that:
- result.changed
- 'result.pending_modified_values.storage_type == "gp3"'
- 'result.storage_type == "gp2"'

- name: Modify the storage type without immediate application - idempotent
rds_instance:
id: '{{ instance_id }}'
state: present
storage_type: gp3
apply_immediately: false
register: result
check_mode: yes

- assert:
that:
- not result.changed
- 'result.pending_modified_values.storage_type == "gp3"'
- 'result.storage_type == "gp2"'

- name: Modify the storage type back to gp2 without immediate application
rds_instance:
id: '{{ instance_id }}'
state: present
storage_type: gp2
apply_immediately: false
register: result

- assert:
that:
- result.changed
- 'result.pending_modified_values == {}'
- 'result.storage_type == "gp2"'

- name: Modify the instance name without immediate application - check_mode
rds_instance:
Expand Down