diff --git a/reconcile/test/utils/test_terraform_client.py b/reconcile/test/utils/test_terraform_client.py index 70b355c815..91609bf578 100644 --- a/reconcile/test/utils/test_terraform_client.py +++ b/reconcile/test/utils/test_terraform_client.py @@ -759,6 +759,39 @@ def test_validate_blue_green_update_requirements_with_storage_type_change( ) +def test_validate_db_upgrade_blue_green_update_no_version_change( + mocker: MockerFixture, aws_api: AWSApi, tf: tfclient.TerraformClient +) -> None: + aws_api.get_db_valid_upgrade_target.return_value = [ # type: ignore[attr-defined] + {"Engine": "postgres", "EngineVersion": "11.12", "IsMajorVersionUpgrade": False} + ] + aws_api.describe_db_parameter_group.return_value = {"rds.logical_replication": "1"} # type: ignore[attr-defined] + + mocked_logging = mocker.patch("reconcile.utils.terraform_client.logging") + + tf.validate_db_upgrade( + account_name="a1", + resource_name="test-database-1", + resource_change={ + "before": { + "engine": "postgres", + "engine_version": "11.12", + "availability_zone": "us-east-1a", + "parameter_group_name": "test-pg", + "replicas": [], + "replicate_source_db": "", + }, + "after": { + "engine": "postgres", + "engine_version": "11.12", + "blue_green_update": [{"enabled": True}], + }, + }, + ) + + mocked_logging.error.assert_not_called() + + def test_check_output_debug( tf: tfclient.TerraformClient, mocker: MockerFixture, diff --git a/reconcile/utils/terraform_client.py b/reconcile/utils/terraform_client.py index 1b49956136..0c80eef261 100644 --- a/reconcile/utils/terraform_client.py +++ b/reconcile/utils/terraform_client.py @@ -771,38 +771,37 @@ def validate_db_upgrade( before_version = before["engine_version"] after = resource_change["after"] after_version = after["engine_version"] - if after_version == before_version: - return - region_name = get_region_from_availability_zone(before["availability_zone"]) - if self._aws_api is not None: - valid_upgrade_target = self._aws_api.get_db_valid_upgrade_target( - account_name, engine, before_version, region_name=region_name - ) - target = next( - ( - t - for t in valid_upgrade_target - if t["EngineVersion"] == after_version - ), - None, - ) - if target is None: - logging.error( - f"Cannot upgrade RDS instance: {resource_name} " - f"from {before_version} to {after_version}" + if after_version != before_version: + region_name = get_region_from_availability_zone(before["availability_zone"]) + if self._aws_api is not None: + valid_upgrade_target = self._aws_api.get_db_valid_upgrade_target( + account_name, engine, before_version, region_name=region_name ) - return - allow_major_version_upgrade = after.get( - "allow_major_version_upgrade", - False, - ) - if target["IsMajorVersionUpgrade"] and not allow_major_version_upgrade: - logging.error( - "allow_major_version_upgrade is not enabled for upgrading RDS instance: " - f"{resource_name} to a new major version." + target = next( + ( + t + for t in valid_upgrade_target + if t["EngineVersion"] == after_version + ), + None, ) - return + if target is None: + logging.error( + f"Cannot upgrade RDS instance: {resource_name} " + f"from {before_version} to {after_version}" + ) + return + allow_major_version_upgrade = after.get( + "allow_major_version_upgrade", + False, + ) + if target["IsMajorVersionUpgrade"] and not allow_major_version_upgrade: + logging.error( + "allow_major_version_upgrade is not enabled for upgrading RDS instance: " + f"{resource_name} to a new major version." + ) + return blue_green_update = after.get("blue_green_update", []) if blue_green_update and blue_green_update[0]["enabled"]: