From bacb6eaaf71be96d619cc1c8f65fb6b189d81bf2 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Wed, 27 Oct 2021 16:28:27 +0200 Subject: [PATCH] Improve error handling rds.py for rds_cluster Signed-off-by: Alina Buzachis --- plugins/module_utils/rds.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/rds.py b/plugins/module_utils/rds.py index 221b92eff3e..ef84e11bb00 100644 --- a/plugins/module_utils/rds.py +++ b/plugins/module_utils/rds.py @@ -82,7 +82,10 @@ def handle_errors(module, exception, method_name, parameters): changed = True error_code = exception.response['Error']['Code'] - if method_name == 'modify_db_instance' and error_code == 'InvalidParameterCombination': + if ( + (method_name == 'modify_db_instance' or method_name == 'modify_db_cluster') and + error_code == 'InvalidParameterCombination' + ): if 'No modifications were requested' in to_text(exception): changed = False elif 'ModifyDbCluster API' in to_text(exception): @@ -94,6 +97,11 @@ def handle_errors(module, exception, method_name, parameters): changed = False else: module.fail_json_aws(exception, msg='Unable to {0}'.format(get_rds_method_attribute(method_name, module).operation_description)) + elif method_name == 'promote_read_replica_db_cluster' and error_code == 'InvalidDBClusterStateFault': + if 'DB Cluster that is not a read replica' in to_text(exception): + changed = False + else: + module.fail_json_aws(exception, msg='Unable to {0}'.format(get_rds_method_attribute(method_name, module).operation_description)) elif method_name == 'create_db_instance' and exception.response['Error']['Code'] == 'InvalidParameterValue': accepted_engines = [ 'aurora', 'aurora-mysql', 'aurora-postgresql', 'mariadb', 'mysql', 'oracle-ee', 'oracle-se', @@ -103,6 +111,14 @@ def handle_errors(module, exception, method_name, parameters): module.fail_json_aws(exception, msg='DB engine {0} should be one of {1}'.format(parameters.get('Engine'), accepted_engines)) else: module.fail_json_aws(exception, msg='Unable to {0}'.format(get_rds_method_attribute(method_name, module).operation_description)) + elif method_name == 'create_db_cluster' and exception.response['Error']['Code'] == 'InvalidParameterValue': + accepted_engines = [ + 'aurora', 'aurora-mysql', 'aurora-postgresql' + ] + if parameters.get('Engine') not in accepted_engines: + module.fail_json_aws(exception, msg='DB engine {0} should be one of {1}'.format(parameters.get('Engine'), accepted_engines)) + else: + module.fail_json_aws(exception, msg='Unable to {0}'.format(get_rds_method_attribute(method_name, module).operation_description)) else: module.fail_json_aws(exception, msg='Unable to {0}'.format(get_rds_method_attribute(method_name, module).operation_description)) @@ -122,6 +138,11 @@ def call_method(client, module, method_name, parameters): if wait: wait_for_status(client, module, module.params['db_instance_identifier'], method_name) result = AWSRetry.jittered_backoff(catch_extra_error_codes=['InvalidDBInstanceState'])(method)(**parameters) + elif method_name == 'modify_db_cluster': + # check if cluster is in an available state first, if possible + if wait: + wait_for_status(client, module, module.params['db_cluster_identifier'], method_name) + result = AWSRetry.jittered_backoff(catch_extra_error_codes=['InvalidDBClusterStateFault'])(method)(**parameters) else: result = AWSRetry.jittered_backoff()(method)(**parameters) except (BotoCoreError, ClientError) as e: