From 7e5884f13849be1f0337e01381e22aeb52d5975d Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Tue, 10 Dec 2024 15:47:42 -0500 Subject: [PATCH 1/4] Fix InvalidParameterValue error when removing serverlessv2_scaling_configuration --- internal/service/rds/cluster.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/internal/service/rds/cluster.go b/internal/service/rds/cluster.go index b3cc66ffff0..9a95c5d4d1a 100644 --- a/internal/service/rds/cluster.go +++ b/internal/service/rds/cluster.go @@ -547,7 +547,22 @@ func resourceCluster() *schema.Resource { names.AttrMaxCapacity: { Type: schema.TypeFloat, Required: true, - ValidateFunc: validation.FloatBetween(0, 256), + ValidateFunc: validation.FloatBetween(0.5, 256), + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + // Handles a breaking regression. On v5.79.0 and earlier, + // serverlessv2_scaling_configuration block could be removed from + // configuration. Although doing so doesn't actually remove the scaling + // configuration from AWS this dsf does allow the user to remove the block + // from their configuration without perpetual diffs. + // https://github.com/hashicorp/terraform-provider-aws/issues/40473 + config := d.GetRawConfig() + raw := config.GetAttr("serverlessv2_scaling_configuration") + + if raw.LengthInt() == 0 && (old != "0" && old != "") && (new == "0" || new == "") { + return true + } + return false + }, }, "min_capacity": { Type: schema.TypeFloat, @@ -2164,7 +2179,9 @@ func expandServerlessV2ScalingConfiguration(tfMap map[string]interface{}) *types apiObject := &types.ServerlessV2ScalingConfiguration{} - if v, ok := tfMap[names.AttrMaxCapacity].(float64); ok { + // Removing the serverlessv2_scaling_configuration block from config for an update, sets max_capacity + // to 0. Sending 0 to the API causes an error. + if v, ok := tfMap[names.AttrMaxCapacity].(float64); ok && v != 0.0 { apiObject.MaxCapacity = aws.Float64(v) } From 8237abb693d6102ae04fb5c9ade20156eb65a33b Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Tue, 10 Dec 2024 15:48:57 -0500 Subject: [PATCH 2/4] Add tests for regressions being fixed --- internal/service/rds/cluster_test.go | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/internal/service/rds/cluster_test.go b/internal/service/rds/cluster_test.go index 9d6b4875949..d17a56a207d 100644 --- a/internal/service/rds/cluster_test.go +++ b/internal/service/rds/cluster_test.go @@ -2123,6 +2123,43 @@ func TestAccRDSCluster_serverlessV2ScalingConfiguration(t *testing.T) { }) } +func TestAccRDSCluster_serverlessV2ScalingRemoved(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var dbCluster types.DBCluster + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_rds_cluster.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.RDSServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckClusterDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccClusterConfig_serverlessV2ScalingConfiguration(rName, 64.0, 2.5), + Check: resource.ComposeTestCheckFunc( + testAccCheckClusterExists(ctx, resourceName, &dbCluster), + resource.TestCheckResourceAttr(resourceName, "serverlessv2_scaling_configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "serverlessv2_scaling_configuration.0.max_capacity", "64"), + resource.TestCheckResourceAttr(resourceName, "serverlessv2_scaling_configuration.0.min_capacity", "2.5"), + resource.TestCheckResourceAttrSet(resourceName, "serverlessv2_scaling_configuration.0.seconds_until_auto_pause"), + ), + }, + { + Config: testAccClusterConfig_serverlessV2ScalingRemoved(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckClusterExists(ctx, resourceName, &dbCluster), + ), + }, + }, + }) +} + // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/11698 func TestAccRDSCluster_Scaling_defaultMinCapacity(t *testing.T) { ctx := acctest.Context(t) @@ -5244,6 +5281,25 @@ resource "aws_rds_cluster" "test" { `, tfrds.ClusterEngineAuroraPostgreSQL, rName, maxCapacity, minCapacity) } +func testAccClusterConfig_serverlessV2ScalingRemoved(rName string) string { + return fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = ["db.serverless"] +} + +resource "aws_rds_cluster" "test" { + cluster_identifier = %[2]q + master_password = "avoid-plaintext-passwords" + master_username = "tfacctest" + skip_final_snapshot = true + engine = data.aws_rds_orderable_db_instance.test.engine + engine_version = data.aws_rds_orderable_db_instance.test.engine_version +} +`, tfrds.ClusterEngineAuroraPostgreSQL, rName) +} + func testAccClusterConfig_serverlessV2ScalingConfigurationWithSecondsUntilAutoPause(rName string, maxCapacity, minCapacity float64, secondsUntilAutoPause int) string { return fmt.Sprintf(` data "aws_rds_orderable_db_instance" "test" { From d2b91552040082f70c30b078916b0ca14159642a Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Tue, 10 Dec 2024 15:51:56 -0500 Subject: [PATCH 3/4] Add changelog --- .changelog/40511.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/40511.txt diff --git a/.changelog/40511.txt b/.changelog/40511.txt new file mode 100644 index 00000000000..8d8744abbc1 --- /dev/null +++ b/.changelog/40511.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_rds_cluster: Fix `InvalidParameterValue: Serverless v2 maximum capacity 0.0 isn't valid. The maximum capacity must be at least 1.0.` errors when removing `serverlessv2_scaling_configuration` in an update +``` \ No newline at end of file From 288809a31e67c75f11fad976f024c8376ff80d4b Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Tue, 10 Dec 2024 16:35:41 -0500 Subject: [PATCH 4/4] Update valid range --- internal/service/rds/cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/rds/cluster.go b/internal/service/rds/cluster.go index 9a95c5d4d1a..fd93671c274 100644 --- a/internal/service/rds/cluster.go +++ b/internal/service/rds/cluster.go @@ -547,7 +547,7 @@ func resourceCluster() *schema.Resource { names.AttrMaxCapacity: { Type: schema.TypeFloat, Required: true, - ValidateFunc: validation.FloatBetween(0.5, 256), + ValidateFunc: validation.FloatBetween(1, 256), DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { // Handles a breaking regression. On v5.79.0 and earlier, // serverlessv2_scaling_configuration block could be removed from