fix(rds): apply DBInstanceClass, AllocatedStorage and EngineVersion on ModifyDBInstance (#4214)

* fix(rds): apply DBInstanceClass, AllocatedStorage and EngineVersion on ModifyDBInstance

ModifyDBInstance parsed the password, IAM auth, subnet group, option group,
security groups and the backup and monitoring settings, but never read
DBInstanceClass, AllocatedStorage or EngineVersion. A resize or an engine
upgrade returned 200 while DescribeDBInstances kept reporting the values the
instance was created with, so a caller that diffs its configuration against a
read-back saw the same pending change on every run.

The three members move into a DbInstanceScalingChanges record that the handler
fills from the request and the service applies, with the rules the AWS API
reference states for them:

- AllocatedStorage below the current size fails with InvalidParameterCombination
- an increase under 10% is rounded up to 10% greater on PostgreSQL, MySQL and
  MariaDB, and taken as given on SQL Server
- the same size is not a change and is left alone
- a different major EngineVersion needs AllowMajorVersionUpgrade

Floci applies the change immediately rather than deferring it to the preferred
maintenance window: it runs no maintenance window and models no
PendingModifiedValues, so a deferred change would never be applied at all.

* fix(rds): reject a ModifyDBInstance scaling change before applying any member

The scaling members were validated as they were assigned: the class was set,
then the storage was resolved, which can refuse a shrink, then the engine
version was checked, which can refuse a major upgrade. The instance a modify
works on is the stored object rather than a copy, so a request refused at the
second or third step had already written the earlier ones, and a read-back
reported a class the 400 said it never got.

The checks now run in resolveFor, ahead of every setter in modifyDbInstance,
including the password rotation that reaches the running container. applyTo is
left as pure assignment of an already-resolved record.
This commit is contained in:
Abhigya authored and GitHub committed 2026-09-23 11:41:15 -04:00
1 parent daecc6da17
commit f2d6710b24
10 files changed
+598 -16

No files matched your search

@@ -31,6 +31,7 @@ import software.amazon.awssdk.services.rds.model.ModifyOptionGroupResponse;
import software.amazon.awssdk.services.rds.model.OptionConfiguration;
import software.amazon.awssdk.services.rds.model.OptionGroupNotFoundException;
import software.amazon.awssdk.services.rds.model.OptionSetting;
import software.amazon.awssdk.services.rds.model.RdsException;
import software.amazon.awssdk.services.rds.model.Tag;
import java.util.List;
@@ -433,6 +434,49 @@ class RdsControlPlaneTest {
}
}
@Test
@DisplayName("ModifyDBInstance resizes and upgrades an instance, and Describe reports it")
void sdkResizesAndUpgradesAStandaloneInstance() {
String instanceName = TestFixtures.uniqueName("rds-resize-db");
try {
createDbInstance(rds, instanceName, "resize-secret");
DBInstance modified = rds.modifyDBInstance(b -> b
.dbInstanceIdentifier(instanceName)
.dbInstanceClass("db.t3.large")
.allocatedStorage(100)
.engineVersion("16.4")).dbInstance();
assertThat(modified.dbInstanceClass()).isEqualTo("db.t3.large");
assertThat(modified.allocatedStorage()).isEqualTo(100);
assertThat(modified.engineVersion()).isEqualTo("16.4");
DBInstance described = rds.describeDBInstances(b -> b.dbInstanceIdentifier(instanceName))
.dbInstances().get(0);
assertThat(described.dbInstanceClass()).isEqualTo("db.t3.large");
assertThat(described.allocatedStorage()).isEqualTo(100);
assertThat(described.engineVersion()).isEqualTo("16.4");
assertThatThrownBy(() -> rds.modifyDBInstance(b -> b
.dbInstanceIdentifier(instanceName).allocatedStorage(50)))
.isInstanceOfSatisfying(RdsException.class, e -> assertThat(
e.awsErrorDetails().errorCode()).isEqualTo("InvalidParameterCombination"));
assertThatThrownBy(() -> rds.modifyDBInstance(b -> b
.dbInstanceIdentifier(instanceName).engineVersion("17.2")))
.isInstanceOfSatisfying(RdsException.class, e -> assertThat(
e.awsErrorDetails().errorCode()).isEqualTo("InvalidParameterCombination"));
DBInstance upgraded = rds.modifyDBInstance(b -> b
.dbInstanceIdentifier(instanceName)
.engineVersion("17.2")
.allowMajorVersionUpgrade(true)).dbInstance();
assertThat(upgraded.engineVersion()).isEqualTo("17.2");
} finally {
deleteDbInstance(rds, instanceName);
}
}
@Test
void sdkCopiesModifiesAndDeletesManualSnapshots() {
String instanceName = TestFixtures.uniqueName("rds-snap-db");