From 9e44560e59cca460910a14fdb93f5f7a58f1d481 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Thu, 13 Oct 2022 14:21:04 -0700 Subject: [PATCH 1/5] fail on trying to modify parameter group engine/family --- plugins/modules/rds_param_group.py | 7 +++++++ .../targets/rds_param_group/defaults/main.yml | 1 + .../targets/rds_param_group/tasks/main.yml | 20 +++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/plugins/modules/rds_param_group.py b/plugins/modules/rds_param_group.py index 0bb42e0afa0..326d219c5f4 100644 --- a/plugins/modules/rds_param_group.py +++ b/plugins/modules/rds_param_group.py @@ -35,6 +35,8 @@ - The type of database for this group. - Please use following command to get list of all supported db engines and their respective versions. - '# aws rds describe-db-engine-versions --query "DBEngineVersions[].DBParameterGroupFamily"' + - The DB parameter group family can't be changed when updating a DB parameter group. + See U(https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbparametergroup.html) - Required for I(state=present). type: str immediate: @@ -266,6 +268,11 @@ def ensure_present(module, connection): module.fail_json_aws(e, msg="Couldn't create parameter group") else: group = response['DBParameterGroups'][0] + db_parameter_group_family = group['DBParameterGroupFamily'] + + if module.params.get('engine') != db_parameter_group_family: + module.fail_json(msg="The DB parameter group family (engine) can't be changed when updating a DB parameter group.") + if tags: changed = update_tags(module, connection, group, tags) diff --git a/tests/integration/targets/rds_param_group/defaults/main.yml b/tests/integration/targets/rds_param_group/defaults/main.yml index d9636646b79..c1a363b3a1d 100644 --- a/tests/integration/targets/rds_param_group/defaults/main.yml +++ b/tests/integration/targets/rds_param_group/defaults/main.yml @@ -2,6 +2,7 @@ rds_param_group: name: '{{ resource_prefix}}rds-param-group' description: Test group for rds_param_group Ansible module engine: postgres9.6 + engine_to_modify_to: postgres10 rds_long_param_list: application_name: Test diff --git a/tests/integration/targets/rds_param_group/tasks/main.yml b/tests/integration/targets/rds_param_group/tasks/main.yml index 889bf876aa3..14528d892c9 100644 --- a/tests/integration/targets/rds_param_group/tasks/main.yml +++ b/tests/integration/targets/rds_param_group/tasks/main.yml @@ -123,6 +123,26 @@ - result.tags["Test"] == '123' # ============================================================ + + - name: test modifying rds parameter group engine/family + rds_param_group: + name: '{{ rds_param_group.name }}' + engine: '{{ rds_param_group.engine_to_modify_to }}' + description: '{{ rds_param_group.description }}' + state: present + tags: + Environment: test + Test: 123 + register: result + ignore_errors: true + + - name: adding numeric tag just silently converts + assert: + that: + - not result.changed + - result.failed + + # ============================================================ - name: test tagging existing group - CHECK_MODE rds_param_group: name: '{{ rds_param_group.name }}' From c953facd2c86b0e84be809fe890684b1a63ac23f Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Thu, 13 Oct 2022 15:04:11 -0700 Subject: [PATCH 2/5] Added changelogs fragment --- .../fragments/1169-rds_param_group-fail-on-updating-engine.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/1169-rds_param_group-fail-on-updating-engine.yml diff --git a/changelogs/fragments/1169-rds_param_group-fail-on-updating-engine.yml b/changelogs/fragments/1169-rds_param_group-fail-on-updating-engine.yml new file mode 100644 index 00000000000..4d6e803c42e --- /dev/null +++ b/changelogs/fragments/1169-rds_param_group-fail-on-updating-engine.yml @@ -0,0 +1,2 @@ +bugfixes: +- rds_param_group - added a check to fail the task while modifying/updating rds_param_group if trying to change DB parameter group family. (https://github.com/ansible-collections/amazon.aws/pull/1169). From 6c41bc31445bb456fd8e318e4b5f1c95406ec97a Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Thu, 13 Oct 2022 18:32:55 -0700 Subject: [PATCH 3/5] Fix integration test task name --- tests/integration/targets/rds_param_group/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/rds_param_group/tasks/main.yml b/tests/integration/targets/rds_param_group/tasks/main.yml index 14528d892c9..0985fe306ac 100644 --- a/tests/integration/targets/rds_param_group/tasks/main.yml +++ b/tests/integration/targets/rds_param_group/tasks/main.yml @@ -136,7 +136,7 @@ register: result ignore_errors: true - - name: adding numeric tag just silently converts + - name: verify that modifying rds param group engine/family failed assert: that: - not result.changed From fbab7961e7190d62b99213d79b7f32090f1b8ba1 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 18 Oct 2022 11:55:52 -0700 Subject: [PATCH 4/5] show warning instead of failure on modifying engine/family --- plugins/modules/rds_param_group.py | 4 ++-- tests/integration/targets/rds_param_group/tasks/main.yml | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/modules/rds_param_group.py b/plugins/modules/rds_param_group.py index 326d219c5f4..12deba6186d 100644 --- a/plugins/modules/rds_param_group.py +++ b/plugins/modules/rds_param_group.py @@ -35,7 +35,7 @@ - The type of database for this group. - Please use following command to get list of all supported db engines and their respective versions. - '# aws rds describe-db-engine-versions --query "DBEngineVersions[].DBParameterGroupFamily"' - - The DB parameter group family can't be changed when updating a DB parameter group. + - The DB parameter group family is immutable and can't be changed when updating a DB parameter group. See U(https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbparametergroup.html) - Required for I(state=present). type: str @@ -271,7 +271,7 @@ def ensure_present(module, connection): db_parameter_group_family = group['DBParameterGroupFamily'] if module.params.get('engine') != db_parameter_group_family: - module.fail_json(msg="The DB parameter group family (engine) can't be changed when updating a DB parameter group.") + module.warn("The DB parameter group family (engine) can't be changed when updating a DB parameter group.") if tags: changed = update_tags(module, connection, group, tags) diff --git a/tests/integration/targets/rds_param_group/tasks/main.yml b/tests/integration/targets/rds_param_group/tasks/main.yml index 0985fe306ac..7bc2025e2e3 100644 --- a/tests/integration/targets/rds_param_group/tasks/main.yml +++ b/tests/integration/targets/rds_param_group/tasks/main.yml @@ -124,7 +124,7 @@ # ============================================================ - - name: test modifying rds parameter group engine/family + - name: test modifying rds parameter group engine/family (warning displayed) rds_param_group: name: '{{ rds_param_group.name }}' engine: '{{ rds_param_group.engine_to_modify_to }}' @@ -134,13 +134,12 @@ Environment: test Test: 123 register: result - ignore_errors: true - name: verify that modifying rds param group engine/family failed assert: that: - not result.changed - - result.failed + - not result.failed # ============================================================ - name: test tagging existing group - CHECK_MODE From 32c5bb764f7acf4eb9d6eb2e3bdb4bf564963833 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 19 Oct 2022 15:50:58 -0700 Subject: [PATCH 5/5] fix task name for integration test task --- tests/integration/targets/rds_param_group/tasks/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/rds_param_group/tasks/main.yml b/tests/integration/targets/rds_param_group/tasks/main.yml index 7bc2025e2e3..274dbee906a 100644 --- a/tests/integration/targets/rds_param_group/tasks/main.yml +++ b/tests/integration/targets/rds_param_group/tasks/main.yml @@ -135,11 +135,13 @@ Test: 123 register: result - - name: verify that modifying rds param group engine/family failed + - name: verify that modifying rds param group engine/family displays warning assert: that: - not result.changed - not result.failed + - result.warnings is defined + - result.warnings | length > 0 # ============================================================ - name: test tagging existing group - CHECK_MODE