fix(rds): store and describe Iops and StorageThroughput on DB instances (#8777)

CreateDBInstance and ModifyDBInstance accepted Iops and StorageThroughput but dropped them, and DescribeDBInstances returned neither, so a Terraform aws_db_instance that set iops or storage_throughput never converged. Both are now stored from Create and Modify. Describe reports Iops on io1, io2 and gp3 and StorageThroughput on gp3, with the RDS User Guide's gp3 baseline when an instance named neither (12,000 IOPS and 500 MiB/s from 400 GiB, 200 GiB for Oracle, never for SQL Server; 3,000 and 125 otherwise), and StorageThroughput 0 on every other type. Iops on a type without provisioned IOPS, Iops=0 aside, and StorageThroughput off gp3 are refused with InvalidParameterCombination, a create naming Iops and no type defaults to io1, and a type switch drops values the new type does not carry.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-11-19 13:02:39 -04:00
1 parent 623be62f3a
commit 079d4a2813
7 files changed
+285 -10

No files matched your search

@@ -996,7 +996,9 @@ public class RdsQueryHandler {
optionalInt(params.getFirst("MaxAllocatedStorage")),
params.getFirst("StorageType"),
params.getFirst("CACertificateIdentifier"),
params.getFirst("LicenseModel"));
params.getFirst("LicenseModel"),
optionalInt(params.getFirst("Iops")),
optionalInt(params.getFirst("StorageThroughput")));
}
/**
@@ -3408,6 +3410,8 @@ public class RdsQueryHandler {
.elem("MultiAZ", i.isMultiAz())
.elem("AutoMinorVersionUpgrade", i.isAutoMinorVersionUpgrade())
.elem("StorageType", i.getStorageType())
.elem("Iops", iops(i))
.elem("StorageThroughput", storageThroughput(i))
.elem("PubliclyAccessible", i.isPubliclyAccessible())
.elem("AvailabilityZone", i.getAvailabilityZone() != null ? i.getAvailabilityZone() : config.defaultAvailabilityZone())
.elem("PreferredMaintenanceWindow", i.getPreferredMaintenanceWindow() != null
@@ -3501,6 +3505,41 @@ public class RdsQueryHandler {
return xml.build();
}
/** Iops as Describe reports it: on io1, io2 and gp3, the stored value, else the gp3 baseline. */
private static String iops(DbInstance i) {
String type = i.getStorageType();
boolean gp3 = "gp3".equals(type);
if (!gp3 && !"io1".equals(type) && !"io2".equals(type)) {
return null;
}
if (i.getIops() != null) {
return i.getIops().toString();
}
return gp3 ? (gp3BaselineSteppedUp(i) ? "12000" : "3000") : null;
}
/** StorageThroughput as Describe reports it: on gp3 the stored value, else the baseline; 0 on any other type. */
private static String storageThroughput(DbInstance i) {
if (!"gp3".equals(i.getStorageType())) {
return "0";
}
if (i.getStorageThroughput() != null) {
return i.getStorageThroughput().toString();
}
return gp3BaselineSteppedUp(i) ? "500" : "125";
}
/**
* Whether the gp3 baseline has stepped up from 3000 IOPS / 125 MiB/s to 12000 / 500: at 400 GiB
* (Db2, MariaDB, MySQL, PostgreSQL) or 200 GiB (Oracle), never on SQL Server.
* https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Storage.html#gp3-storage
*/
private static boolean gp3BaselineSteppedUp(DbInstance i) {
String engine = instanceEngine(i);
int threshold = engine.startsWith("sqlserver") ? Integer.MAX_VALUE : engine.startsWith("oracle") ? 200 : 400;
return i.getAllocatedStorage() >= threshold;
}
private String vpcSecurityGroupsXml(DbInstance i) {
List<String> groupIds = i.getVpcSecurityGroupIds();
if (groupIds.isEmpty()) {
@@ -817,7 +817,9 @@ public class RdsService implements Resettable, ResourceProvider {
DbInstanceSettings resolvedSettings = withEffectiveWindows(settings, null)
.withKmsKeyId(resolveKmsKeyArn(settings.kmsKeyId(), effectiveRegion));
if (isBlank(dbClusterIdentifier) && !isAuroraEngine(engineParam)) {
resolvedSettings = resolvedSettings.withIopsDefaultType();
resolvedSettings.validateStorageType();
resolvedSettings.validateStorageMembers(null);
} else {
resolvedSettings = resolvedSettings.withStorageType(null);
}
@@ -4144,6 +4146,7 @@ public class RdsService implements Resettable, ResourceProvider {
DbInstanceSettings effective = withEffectiveWindows(settings, instance);
if (isBlank(instance.getDbClusterIdentifier()) && !isAuroraEngine(engineName(instance))) {
effective.validateStorageType();
effective.validateStorageMembers(instance.getStorageType());
} else {
effective = effective.withStorageType(null);
}
@@ -26,6 +26,9 @@ public class DbInstance {
private String dbInstanceClass;
private int allocatedStorage;
private String storageType;
// Null until a request names them; Describe then reports the gp3 baseline for gp3 and omits them otherwise.
private Integer iops;
private Integer storageThroughput;
/** The RDS certificate authority for the instance; null on one stored before it was recorded. */
private String caCertificateIdentifier;
/** The license model the request named; null means the engine's default. */
@@ -149,6 +152,12 @@ public class DbInstance {
public String getStorageType() { return storageType != null ? storageType : DEFAULT_STORAGE_TYPE; }
public void setStorageType(String storageType) { this.storageType = storageType; }
public Integer getIops() { return iops; }
public void setIops(Integer iops) { this.iops = iops; }
public Integer getStorageThroughput() { return storageThroughput; }
public void setStorageThroughput(Integer storageThroughput) { this.storageThroughput = storageThroughput; }
public String getLicenseModel() { return licenseModel; }
public void setLicenseModel(String licenseModel) { this.licenseModel = licenseModel; }
public String getCaCertificateIdentifier() { return caCertificateIdentifier; }
@@ -5,6 +5,7 @@ import io.floci.aws.core.common.BackupWindows;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@@ -29,7 +30,9 @@ public record DbInstanceSettings(Boolean storageEncrypted,
Integer maxAllocatedStorage,
String storageType,
String caCertificateIdentifier,
String licenseModel) {
String licenseModel,
Integer iops,
Integer storageThroughput) {
public DbInstanceSettings(Boolean storageEncrypted, String kmsKeyId, Integer backupRetentionPeriod,
String preferredBackupWindow, String preferredMaintenanceWindow,
Boolean copyTagsToSnapshot, Integer monitoringInterval, String monitoringRoleArn,
@@ -41,7 +44,7 @@ public record DbInstanceSettings(Boolean storageEncrypted,
preferredMaintenanceWindow, copyTagsToSnapshot, monitoringInterval, monitoringRoleArn,
performanceInsightsEnabled, performanceInsightsRetentionPeriod, engineLifecycleSupport,
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType,
caCertificateIdentifier, null);
caCertificateIdentifier, null, null, null);
}
public DbInstanceSettings(Boolean storageEncrypted, String kmsKeyId, Integer backupRetentionPeriod,
@@ -216,7 +219,7 @@ public record DbInstanceSettings(Boolean storageEncrypted,
monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,
performanceInsightsRetentionPeriod, engineLifecycleSupport,
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType,
caCertificateIdentifier, licenseModel);
caCertificateIdentifier, licenseModel, iops, storageThroughput);
}
public DbInstanceSettings withKmsKeyId(String resolvedKmsKeyId) {
@@ -225,7 +228,7 @@ public record DbInstanceSettings(Boolean storageEncrypted,
monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,
performanceInsightsRetentionPeriod, engineLifecycleSupport,
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType,
caCertificateIdentifier, licenseModel);
caCertificateIdentifier, licenseModel, iops, storageThroughput);
}
public DbInstanceSettings withStorageType(String resolvedStorageType) {
@@ -234,7 +237,7 @@ public record DbInstanceSettings(Boolean storageEncrypted,
monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,
performanceInsightsRetentionPeriod, engineLifecycleSupport,
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, resolvedStorageType,
caCertificateIdentifier, licenseModel);
caCertificateIdentifier, licenseModel, iops, storageThroughput);
}
/** The same settings with the CA certificate the service resolved. */
@@ -244,7 +247,12 @@ public record DbInstanceSettings(Boolean storageEncrypted,
monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,
performanceInsightsRetentionPeriod, engineLifecycleSupport,
enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage, storageType,
resolvedCaCertificateIdentifier, licenseModel);
resolvedCaCertificateIdentifier, licenseModel, iops, storageThroughput);
}
/** Create's documented default: "io1, if the Iops parameter is specified". */
public DbInstanceSettings withIopsDefaultType() {
return storageType == null && iops != null && iops != 0 ? withStorageType("io1") : this;
}
public void validateStorageType() {
@@ -296,6 +304,7 @@ public record DbInstanceSettings(Boolean storageEncrypted,
instance.setEnabledCloudwatchLogsExports(
logExportChanges.applyTo(instance.getEnabledCloudwatchLogsExports()));
}
String previousType = instance.getStorageType();
if (storageType != null) {
instance.setStorageType(storageType);
}
@@ -308,5 +317,45 @@ public record DbInstanceSettings(Boolean storageEncrypted,
if (licenseModel != null && !licenseModel.isBlank()) {
instance.setLicenseModel(licenseModel);
}
if (iops != null) {
instance.setIops(iops);
}
if (storageThroughput != null) {
instance.setStorageThroughput(storageThroughput);
}
// One normalisation after the merge: a stored value the resulting type doesn't carry is dropped, and an
// Iops carried over from the other family (io <-> gp3) is dropped unless this request set one, so
// Describe reports the baseline rather than a figure that belonged to the old type.
String resolved = instance.getStorageType();
if (!"gp3".equals(resolved)) {
instance.setStorageThroughput(null);
}
if (iopsFamily(resolved) == null || (iops == null && !Objects.equals(iopsFamily(previousType), iopsFamily(resolved)))) {
instance.setIops(null);
}
}
private static String iopsFamily(String type) {
return "gp3".equals(type) ? "gp3" : "io1".equals(type) || "io2".equals(type) ? "io" : null;
}
/**
* Refuses Iops or StorageThroughput on a storage type that doesn't carry it, as the Rust reference does
* (InvalidParameterCombination). Rust checks on Modify only; Floci checks Create too. {@code currentType} is the instance's type on Modify, null on Create.
*/
public void validateStorageMembers(String currentType) {
String resolved = storageType != null ? storageType : currentType;
if (resolved == null) {
return;
}
// Iops=0 is how a modify says "back to standard storage", so it is no Iops at all
if (iops != null && iops != 0 && iopsFamily(resolved) == null) {
throw new AwsException("InvalidParameterCombination",
"Iops can't be specified for storage type " + resolved + ".", 400);
}
if (storageThroughput != null && !"gp3".equals(resolved)) {
throw new AwsException("InvalidParameterCombination",
"StorageThroughput can't be specified for storage type " + resolved + ".", 400);
}
}
}