Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RDS instance bug where switching to IO2 from GP needs the allocated storage set #37257

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading