From 51e8ef9e0cec526a674e534618a56dfb995f476f Mon Sep 17 00:00:00 2001 From: Igshaan Mesias Date: Fri, 19 Aug 2022 11:51:52 +0200 Subject: [PATCH 1/6] Fix `DBClusterParameterGroupName` Key Error when comparing state. --- plugins/modules/rds_cluster.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/modules/rds_cluster.py b/plugins/modules/rds_cluster.py index 68e0ef17fc9..e774e7a66cd 100644 --- a/plugins/modules/rds_cluster.py +++ b/plugins/modules/rds_cluster.py @@ -833,6 +833,11 @@ def changing_cluster_options(modify_params, current_cluster): if desired_vpc_sgs: changing_params['VpcSecurityGroupIds'] = desired_vpc_sgs + desired_db_cluster_parameter_group = modify_params.pop("DBClusterParameterGroupName", None) + if desired_db_cluster_parameter_group: + if desired_db_cluster_parameter_group != current_cluster["DBClusterParameterGroup"]: + changing_params["DBClusterParameterGroupName"] = desired_db_cluster_parameter_group + for param in modify_params: if modify_params[param] != current_cluster[param]: changing_params[param] = modify_params[param] From 7d2f5e805334ab11121103a2edc10ea803f43d33 Mon Sep 17 00:00:00 2001 From: Igshaan Mesias Date: Fri, 19 Aug 2022 12:51:57 +0200 Subject: [PATCH 2/6] Add changelog fragment for bugfix --- changelogs/fragments/1417-cluster-param-group-keyerror.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/1417-cluster-param-group-keyerror.yml diff --git a/changelogs/fragments/1417-cluster-param-group-keyerror.yml b/changelogs/fragments/1417-cluster-param-group-keyerror.yml new file mode 100644 index 00000000000..823c2c85b96 --- /dev/null +++ b/changelogs/fragments/1417-cluster-param-group-keyerror.yml @@ -0,0 +1,2 @@ +bugfixes: +- rds_cluster - fixes bug where specifiying an rds cluster parameter group raises a `KeyError` (https://github.com/ansible-collections/community.aws/pull/1417). From a0584a28fdaa813521434af8d5a8ef0405d6b32d Mon Sep 17 00:00:00 2001 From: Igshaan Mesias Date: Fri, 19 Aug 2022 21:43:11 +0200 Subject: [PATCH 3/6] Expand integration tests for parameter group case. --- .../roles/rds_cluster/defaults/main.yml | 1 + .../roles/rds_cluster/tasks/test_modify.yml | 66 ++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/rds_cluster/roles/rds_cluster/defaults/main.yml b/tests/integration/targets/rds_cluster/roles/rds_cluster/defaults/main.yml index f1fe2137b08..07227eca394 100644 --- a/tests/integration/targets/rds_cluster/roles/rds_cluster/defaults/main.yml +++ b/tests/integration/targets/rds_cluster/roles/rds_cluster/defaults/main.yml @@ -15,6 +15,7 @@ tags_create: new_cluster_id: 'ansible-test-cluster-{{ tiny_prefix }}-new' new_port: 1155 new_password: 'test-rds_password-new' +new_db_parameter_group_name: 'test-db-parameter-group-{{ tiny_prefix }}-new' # Tag cluster tags_patch: diff --git a/tests/integration/targets/rds_cluster/roles/rds_cluster/tasks/test_modify.yml b/tests/integration/targets/rds_cluster/roles/rds_cluster/tasks/test_modify.yml index b093029b54c..886e9a0a85d 100644 --- a/tests/integration/targets/rds_cluster/roles/rds_cluster/tasks/test_modify.yml +++ b/tests/integration/targets/rds_cluster/roles/rds_cluster/tasks/test_modify.yml @@ -14,7 +14,7 @@ that: - not _result_delete_db_cluster.changed ignore_errors: yes - + - name: Create a DB cluster rds_cluster: id: "{{ cluster_id }}" @@ -154,6 +154,61 @@ - "'tags' in _result_modify_id" - "'vpc_security_groups' in _result_modify_id" + - name: Check if DB cluster parameter group exists + command: 'aws rds describe-db-cluster-parameter-groups --db-cluster-parameter-group-name {{ new_db_parameter_group_name }}' + environment: + AWS_ACCESS_KEY_ID: "{{ aws_access_key }}" + AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}" + AWS_SESSION_TOKEN: "{{ security_token | default('') }}" + AWS_DEFAULT_REGION: "{{ aws_region }}" + register: _result_check_db_parameter_group + ignore_errors: True + changed_when: "_result_check_db_parameter_group.rc == 0" + + - name: Create DB cluster parameter group if not exists + command: 'aws rds create-db-cluster-parameter-group --db-cluster-parameter-group-name {{ new_db_parameter_group_name }} --db-parameter-group-family aurora5.6 --description "Test DB cluster parameter group"' + environment: + AWS_ACCESS_KEY_ID: "{{ aws_access_key }}" + AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}" + AWS_SESSION_TOKEN: "{{ security_token | default('') }}" + AWS_DEFAULT_REGION: "{{ aws_region }}" + register: _result_create_db_parameter_group + when: "_result_check_db_parameter_group.rc == 0" + + + - name: Modify DB cluster parameter group + rds_cluster: + id: "{{ cluster_id }}" + state: present + db_cluster_parameter_group_name: "{{ new_db_parameter_group_name }}" + register: _result_modify_db_parameter_group_name + + - assert: + that: + - _result_modify_db_parameter_group_name.changed + - "'allocated_storage' in _result_modify_db_parameter_group_name" + - _result_modify_db_parameter_group_name.allocated_storage == 1 + - "'cluster_create_time' in _result_modify_db_parameter_group_name" + - _result_modify_db_parameter_group_name.copy_tags_to_snapshot == false + - "'db_cluster_arn' in _result_modify_db_parameter_group_name" + - "_result_modify_db_parameter_group_name.db_cluster_identifier == '{{ cluster_id }}'" + - "'db_cluster_parameter_group' in _result_modify_db_parameter_group_name" + - "'db_cluster_resource_id' in _result_modify_db_parameter_group_name" + - "'endpoint' in _result_modify_db_parameter_group_name" + - "'engine' in _result_modify_db_parameter_group_name" + - _result_modify_db_parameter_group_name.engine == "{{ engine }}" + - "'engine_mode' in _result_modify_db_parameter_group_name" + - _result_modify_db_parameter_group_name.engine_mode == "provisioned" + - "'engine_version' in _result_modify_db_parameter_group_name" + - "'master_username' in _result_modify_db_parameter_group_name" + - _result_modify_db_parameter_group_name.master_username == "{{ username }}" + - "'port' in _result_modify_db_parameter_group_name" + - _result_modify_db_parameter_group_name.db_cluster_parameter_group == "{{ new_db_parameter_group_name }}" + - "'status' in _result_modify_db_parameter_group_name" + - _result_modify_db_parameter_group_name.status == "available" + - "'tags' in _result_modify_db_parameter_group_name" + - "'vpc_security_groups' in _result_modify_db_parameter_group_name" + - name: Delete DB cluster without creating a final snapshot (CHECK MODE) rds_cluster: state: absent @@ -195,3 +250,12 @@ cluster_id: "{{ cluster_id }}" skip_final_snapshot: True ignore_errors: true + + - name: Delete cluster parameter group + command: 'aws rds delete-db-cluster-parameter-group --db-cluster-parameter-group-name {{ new_db_parameter_group_name }}' + environment: + AWS_ACCESS_KEY_ID: "{{ aws_access_key }}" + AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}" + AWS_SESSION_TOKEN: "{{ security_token | default('') }}" + AWS_DEFAULT_REGION: "{{ aws_region }}" + ignore_errors: true From 77f5e166303da780ea3b9f58cdbf3f222cf05a0a Mon Sep 17 00:00:00 2001 From: Igshaan Mesias Date: Mon, 22 Aug 2022 09:31:37 +0200 Subject: [PATCH 4/6] Fix module args for CI job, remove quotes from when clause --- .../rds_cluster/roles/rds_cluster/tasks/test_modify.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/targets/rds_cluster/roles/rds_cluster/tasks/test_modify.yml b/tests/integration/targets/rds_cluster/roles/rds_cluster/tasks/test_modify.yml index 886e9a0a85d..1f6c34ad126 100644 --- a/tests/integration/targets/rds_cluster/roles/rds_cluster/tasks/test_modify.yml +++ b/tests/integration/targets/rds_cluster/roles/rds_cluster/tasks/test_modify.yml @@ -19,7 +19,7 @@ rds_cluster: id: "{{ cluster_id }}" state: present - engine: "{{ engine}}" + engine: "{{ engine }}" username: "{{ username }}" password: "{{ password }}" register: _result_create_source_db_cluster @@ -163,7 +163,7 @@ AWS_DEFAULT_REGION: "{{ aws_region }}" register: _result_check_db_parameter_group ignore_errors: True - changed_when: "_result_check_db_parameter_group.rc == 0" + changed_when: _result_check_db_parameter_group.rc == 0 - name: Create DB cluster parameter group if not exists command: 'aws rds create-db-cluster-parameter-group --db-cluster-parameter-group-name {{ new_db_parameter_group_name }} --db-parameter-group-family aurora5.6 --description "Test DB cluster parameter group"' @@ -173,13 +173,13 @@ AWS_SESSION_TOKEN: "{{ security_token | default('') }}" AWS_DEFAULT_REGION: "{{ aws_region }}" register: _result_create_db_parameter_group - when: "_result_check_db_parameter_group.rc == 0" - + when: _result_check_db_parameter_group.rc != 0 - name: Modify DB cluster parameter group rds_cluster: id: "{{ cluster_id }}" state: present + engine: "{{ engine }}" db_cluster_parameter_group_name: "{{ new_db_parameter_group_name }}" register: _result_modify_db_parameter_group_name From f320fb7a82bc5b9f045fb77305cb2314d6e482ca Mon Sep 17 00:00:00 2001 From: Igshaan Mesias Date: Thu, 25 Aug 2022 15:09:33 +0200 Subject: [PATCH 5/6] Update parameter group name for consistency --- .../targets/rds_cluster/roles/rds_cluster/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/rds_cluster/roles/rds_cluster/defaults/main.yml b/tests/integration/targets/rds_cluster/roles/rds_cluster/defaults/main.yml index 07227eca394..06ac9f319d7 100644 --- a/tests/integration/targets/rds_cluster/roles/rds_cluster/defaults/main.yml +++ b/tests/integration/targets/rds_cluster/roles/rds_cluster/defaults/main.yml @@ -15,7 +15,7 @@ tags_create: new_cluster_id: 'ansible-test-cluster-{{ tiny_prefix }}-new' new_port: 1155 new_password: 'test-rds_password-new' -new_db_parameter_group_name: 'test-db-parameter-group-{{ tiny_prefix }}-new' +new_db_parameter_group_name: 'ansible-test-db-parameter-group-{{ tiny_prefix }}-new' # Tag cluster tags_patch: From e7ba0573d2a8a0378a269017396aab6d7f4be2d0 Mon Sep 17 00:00:00 2001 From: Igshaan Mesias Date: Thu, 25 Aug 2022 15:10:05 +0200 Subject: [PATCH 6/6] Use `new_cluster_id` as prior test renamed the cluster --- .../rds_cluster/roles/rds_cluster/tasks/test_modify.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/rds_cluster/roles/rds_cluster/tasks/test_modify.yml b/tests/integration/targets/rds_cluster/roles/rds_cluster/tasks/test_modify.yml index 1f6c34ad126..1d0187f2b93 100644 --- a/tests/integration/targets/rds_cluster/roles/rds_cluster/tasks/test_modify.yml +++ b/tests/integration/targets/rds_cluster/roles/rds_cluster/tasks/test_modify.yml @@ -177,10 +177,10 @@ - name: Modify DB cluster parameter group rds_cluster: - id: "{{ cluster_id }}" + id: "{{ new_cluster_id }}" state: present - engine: "{{ engine }}" db_cluster_parameter_group_name: "{{ new_db_parameter_group_name }}" + apply_immediately: True register: _result_modify_db_parameter_group_name - assert: