From ee3cd0be860cd57413be9721da83e284835d4a13 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Sat, 16 Dec 2023 00:00:11 +0530 Subject: [PATCH] rds_cluster: add support for ServerlessV2ScalingConfiguration (#1839) rds_cluster: add support for ServerlessV2ScalingConfiguration SUMMARY Fixes #1476 Add support for ServerlessV2ScalingConfiguration in create_db_cluster and modify_db_cluster https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_ServerlessV2ScalingConfiguration.html https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-serverless-v2.html ISSUE TYPE Feature Pull Request COMPONENT NAME rds_cluster ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis Reviewed-by: Helen Bailey Reviewed-by: GomathiselviS --- ...or-serverless_v2_scaling_configuration.yml | 3 + plugins/modules/rds_cluster.py | 36 ++++++ .../rds_cluster_modify/defaults/main.yml | 3 + ...r_serverless_v2_scaling_configuration.yaml | 118 ++++++++++++++++++ .../rds_cluster_modify/tasks/main.yaml | 3 + 5 files changed, 163 insertions(+) create mode 100644 changelogs/fragments/1839-rds_cluster-add-support-for-serverless_v2_scaling_configuration.yml create mode 100644 tests/integration/targets/rds_cluster_modify/tasks/create_update_cluster_serverless_v2_scaling_configuration.yaml diff --git a/changelogs/fragments/1839-rds_cluster-add-support-for-serverless_v2_scaling_configuration.yml b/changelogs/fragments/1839-rds_cluster-add-support-for-serverless_v2_scaling_configuration.yml new file mode 100644 index 00000000000..6b822d79b93 --- /dev/null +++ b/changelogs/fragments/1839-rds_cluster-add-support-for-serverless_v2_scaling_configuration.yml @@ -0,0 +1,3 @@ +--- +minor_changes: +- rds_cluster - Add support for ServerlessV2ScalingConfiguration to create and modify cluster operations (https://github.com/ansible-collections/amazon.aws/pull/1839). diff --git a/plugins/modules/rds_cluster.py b/plugins/modules/rds_cluster.py index 52bc0dce4d8..578b8247fbd 100644 --- a/plugins/modules/rds_cluster.py +++ b/plugins/modules/rds_cluster.py @@ -350,6 +350,24 @@ - The prefix for all of the file names that contain the data used to create the Amazon Aurora DB cluster. - If you do not specify a SourceS3Prefix value, then the Amazon Aurora DB cluster is created by using all of the files in the Amazon S3 bucket. type: str + serverless_v2_scaling_configuration: + description: + - Contains the scaling configuration of an Aurora Serverless v2 DB cluster. + type: dict + suboptions: + min_capacity: + description: + - The minimum number of Aurora capacity units (ACUs) for a DB instance in an Aurora Serverless v2 cluster. + - ACU values can be specified in in half-step increments, such as C(8), C(8.5), C(9), and so on. + - The smallest possible value is C(0.5). + type: float + max_capacity: + description: + - The maximum number of Aurora capacity units (ACUs) for a DB instance in an Aurora Serverless v2 cluster. + - ACU values can be specified in in half-step increments, such as C(40), C(40.5), C(41), and so on. + - The largest possible value is C(128). + type: float + version_added: 7.2.0 skip_final_snapshot: description: - Whether a final DB cluster snapshot is created before the DB cluster is deleted. @@ -690,6 +708,15 @@ returned: always type: str sample: rds-cluster-demo.cluster-ro-cvlrtwiennww.us-east-1.rds.amazonaws.com +serverless_v2_scaling_configuration: + description: The scaling configuration for an Aurora Serverless v2 DB cluster. + returned: when configured + type: dict + sample: { + "max_capacity": 4.5, + "min_capacity": 2.5 + } + version_added: 7.2.0 status: description: The status of the DB cluster. returned: always @@ -821,6 +848,7 @@ def get_create_options(params_dict): "StorageType", "Iops", "EngineMode", + "ServerlessV2ScalingConfiguration", ] return dict((k, v) for k, v in params_dict.items() if k in options and v is not None) @@ -855,6 +883,7 @@ def get_modify_options(params_dict, force_update_password): "StorageType", "Iops", "EngineMode", + "ServerlessV2ScalingConfiguration", ] modify_options = dict((k, v) for k, v in params_dict.items() if k in options and v is not None) if not force_update_password: @@ -1232,6 +1261,13 @@ def main(): s3_bucket_name=dict(), s3_ingestion_role_arn=dict(), s3_prefix=dict(), + serverless_v2_scaling_configuration=dict( + type="dict", + options=dict( + min_capacity=dict(type="float"), + max_capacity=dict(type="float"), + ), + ), skip_final_snapshot=dict(type="bool", default=False), snapshot_identifier=dict(), source_db_cluster_identifier=dict(), diff --git a/tests/integration/targets/rds_cluster_modify/defaults/main.yml b/tests/integration/targets/rds_cluster_modify/defaults/main.yml index a3a1543cf17..ccfc6d3d25a 100644 --- a/tests/integration/targets/rds_cluster_modify/defaults/main.yml +++ b/tests/integration/targets/rds_cluster_modify/defaults/main.yml @@ -18,6 +18,9 @@ test_engine: aurora-mysql test_engine_version: 8.0 test_instance_class: db.r5.large +min_capacity: 2.5 +max_capacity: 4.5 + # Global cluster parameters ================================ test_global_cluster_name: ansible-test-global-{{ tiny_prefix }} diff --git a/tests/integration/targets/rds_cluster_modify/tasks/create_update_cluster_serverless_v2_scaling_configuration.yaml b/tests/integration/targets/rds_cluster_modify/tasks/create_update_cluster_serverless_v2_scaling_configuration.yaml new file mode 100644 index 00000000000..e97fcd01133 --- /dev/null +++ b/tests/integration/targets/rds_cluster_modify/tasks/create_update_cluster_serverless_v2_scaling_configuration.yaml @@ -0,0 +1,118 @@ +--- +- name: Run tests for testing serverless v2 scaling configuration + block: + - name: Create a cluster (check_mode) + amazon.aws.rds_cluster: + db_cluster_identifier: "{{ cluster_id }}" + region: "{{ aws_region }}" + engine: "{{ test_engine }}" + engine_version: "{{ test_engine_version }}" + username: "{{ username }}" + password: "{{ password }}" + serverless_v2_scaling_configuration: + min_capacity: "{{ min_capacity }}" + max_capacity: "{{ max_capacity }}" + check_mode: true + register: create_result_check_mode + + - name: Get RDS cluster info + amazon.aws.rds_cluster_info: + db_cluster_identifier: "{{ cluster_id }}" + region: "{{ aws_region }}" + register: result + + - assert: + that: + - create_result_check_mode is changed + - create_result_check_mode is not failed + - result.clusters | length == 0 + + - name: Create a cluster + amazon.aws.rds_cluster: + db_cluster_identifier: "{{ cluster_id }}" + region: "{{ aws_region }}" + engine: "{{ test_engine }}" + engine_version: "{{ test_engine_version }}" + username: "{{ username }}" + password: "{{ password }}" + serverless_v2_scaling_configuration: + min_capacity: "{{ min_capacity }}" + max_capacity: "{{ max_capacity }}" + register: create_result + + - name: Get RDS cluster info + amazon.aws.rds_cluster_info: + db_cluster_identifier: "{{ cluster_id }}" + region: "{{ aws_region }}" + register: result + + - assert: + that: + - create_result is changed + - create_result is not failed + - result.clusters[0].serverless_v2_scaling_configuration is defined + - result.clusters[0].serverless_v2_scaling_configuration.min_capacity == 2.5 + - result.clusters[0].serverless_v2_scaling_configuration.max_capacity == 4.5 + + - name: Modify cluster - update serverless v2 scaling configuration (check_mode) + amazon.aws.rds_cluster: + db_cluster_identifier: "{{ cluster_id }}" + region: "{{ aws_region }}" + engine: "{{ test_engine }}" + username: "{{ username }}" + password: "{{ password }}" + serverless_v2_scaling_configuration: + min_capacity: 2 + max_capacity: 5 + check_mode: true + register: modify_result_check_mode + + - name: Get RDS cluster info + amazon.aws.rds_cluster_info: + db_cluster_identifier: "{{ cluster_id }}" + region: "{{ aws_region }}" + register: result + + - assert: + that: + - modify_result_check_mode is changed + - modify_result_check_mode is not failed + - result.clusters[0].serverless_v2_scaling_configuration is defined + - result.clusters[0].serverless_v2_scaling_configuration.min_capacity != 2 + - result.clusters[0].serverless_v2_scaling_configuration.max_capacity != 5 + + - name: Modify cluster - update serverless v2 scaling configuration + amazon.aws.rds_cluster: + db_cluster_identifier: "{{ cluster_id }}" + region: "{{ aws_region }}" + engine: "{{ test_engine }}" + username: "{{ username }}" + password: "{{ password }}" + serverless_v2_scaling_configuration: + min_capacity: 2 + max_capacity: 5 + register: modify_result + + - name: Get RDS cluster info + amazon.aws.rds_cluster_info: + db_cluster_identifier: "{{ cluster_id }}" + region: "{{ aws_region }}" + register: result + + - assert: + that: + - modify_result is changed + - modify_result is not failed + - result.clusters[0].serverless_v2_scaling_configuration is defined + - result.clusters[0].serverless_v2_scaling_configuration.min_capacity == 2 + - result.clusters[0].serverless_v2_scaling_configuration.max_capacity == 5 + + always: + + - name: Delete DB cluster created in this test + amazon.aws.rds_cluster: + cluster_id: "{{ cluster_id }}" + region: "{{ aws_region }}" + skip_final_snapshot: true + state: absent + ignore_errors: true \ No newline at end of file diff --git a/tests/integration/targets/rds_cluster_modify/tasks/main.yaml b/tests/integration/targets/rds_cluster_modify/tasks/main.yaml index 37af5da3803..2a5f07dbb7f 100644 --- a/tests/integration/targets/rds_cluster_modify/tasks/main.yaml +++ b/tests/integration/targets/rds_cluster_modify/tasks/main.yaml @@ -11,6 +11,9 @@ # - name: Run tests for testing remove cluster from global db # import_tasks: remove_from_global_db.yaml + - name: Run tests for testing serverless v2 scaling configuration + import_tasks: create_update_cluster_serverless_v2_scaling_configuration.yaml + - name: Ensure the resource doesn't exist amazon.aws.rds_cluster: id: "{{ cluster_id }}"