Skip to content

Commit

Permalink
Merge pull request #37257 from nhenjes/b-aws_rds_instance-storage-cha…
Browse files Browse the repository at this point in the history
…nge-fix-36648

Fix RDS instance bug where switching to IO2 from GP needs the allocated storage set
  • Loading branch information
YakDriver authored Nov 22, 2024
2 parents 56e2b26 + e2f9749 commit 2d557a8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
60 changes: 60 additions & 0 deletions internal/service/rds/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,37 @@ func TestAccRDSCluster_storageTypeIo2(t *testing.T) {
})
}

func TestAccRDSCluster_storageTypeGeneralPurposeToProvisionedIOPS(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_db_instance.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_storageChange(rName, "gp3"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "storage_type", "gp3"),
),
},
{
Config: testAccClusterConfig_storageChange(rName, "io2"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, names.AttrStorageType, "io2"),
),
},
},
})
}

// For backwards compatibility, the control plane should always return a blank string even if sending "aurora" as the storage type
func TestAccRDSCluster_storageTypeAuroraReturnsBlank(t *testing.T) {
if testing.Short() {
Expand Down Expand Up @@ -3393,6 +3424,35 @@ resource "aws_rds_cluster" "test" {
`, tfrds.ClusterEngineMySQL, mainInstanceClasses, rName, sType))
}

func testAccClusterConfig_storageChange(rName string, sType string) string {
return acctest.ConfigCompose(
testAccConfig_ClusterSubnetGroup(rName),
fmt.Sprintf(`
data "aws_rds_orderable_db_instance" "test" {
engine = %[1]q
engine_latest_version = true
preferred_instance_classes = [%[2]s]
storage_type = %[4]q
supports_iops = true
supports_clusters = true
}
resource "aws_db_instance" "test" {
apply_immediately = true
instance_class = data.aws_rds_orderable_db_instance.test.instance_class
db_subnet_group_name = aws_db_subnet_group.test.name
engine = data.aws_rds_orderable_db_instance.test.engine
engine_version = data.aws_rds_orderable_db_instance.test.engine_version
storage_type = data.aws_rds_orderable_db_instance.test.storage_type
allocated_storage = 400
iops = 12000
password = "mustbeeightcharaters"
username = "test"
skip_final_snapshot = true
}
`, tfrds.ClusterEnginePostgres, mainInstanceClasses, rName, sType))
}

func testAccClusterConfig_allocatedStorage(rName string) string {
return acctest.ConfigCompose(
testAccConfig_ClusterSubnetGroup(rName),
Expand Down
1 change: 1 addition & 0 deletions internal/service/rds/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2589,6 +2589,7 @@ func dbInstancePopulateModify(input *rds.ModifyDBInstanceInput, d *schema.Resour

if slices.Contains([]string{storageTypeIO1, storageTypeIO2}, aws.ToString(input.StorageType)) {
input.Iops = aws.Int32(int32(d.Get(names.AttrIOPS).(int)))
input.AllocatedStorage = aws.Int32(int32(d.Get("allocated_storage").(int)))
}
}

Expand Down

0 comments on commit 2d557a8

Please sign in to comment.