fix(rds): retain cluster settings and member promotion tiers (#8849)

RDS accepted a cluster's CopyTagsToSnapshot and CloudWatch log exports and an Aurora member's PromotionTier but returned none of them, so Terraform planned changes right after a successful apply. CreateDBCluster and ModifyDBCluster now keep CopyTagsToSnapshot, an explicit false included, and the enabled log exports, with a modify applying CloudwatchLogsExportConfiguration as enable and disable deltas and leaving omitted fields alone. PromotionTier is kept from CreateDBInstance and ModifyDBInstance, defaults to 1 and is refused outside 0 to 15 before anything changes, and both the instance and the cluster member list report it. The new fields persist, and state saved before them loads with the defaults.

Closes #8418
This commit is contained in:
luiseterc authored and GitHub committed 2026-11-18 13:17:50 -04:00
1 parent 1c3a6b615e
commit 72b746be13
7 files changed
+319 -1

No files matched your search

@@ -387,6 +387,8 @@ public class RdsQueryHandler {
try {
DbInstanceSettings settings = instanceSettings(params);
Integer promotionTier = parseIntegerParam(params, "PromotionTier");
RdsService.validatePromotionTier(promotionTier);
List<String> vpcSecurityGroupIds = vpcSecurityGroupIds(params);
Integer requestedPort = parseIntegerParam(params, "Port");
DbInstance instance = service.createDbInstance(id, engine, engineVersion, masterUsername,
@@ -395,6 +397,9 @@ public class RdsQueryHandler {
manageMasterUserPassword, masterUserSecretKmsKeyId, tags, vpcSecurityGroupIds,
optionGroupName, region, autoMinorVersionUpgrade, settings, publiclyAccessible,
requestedPort, deletionProtection);
if (promotionTier != null) {
instance = service.setInstancePromotionTier(region, id, promotionTier);
}
String result = dbInstanceXml(instance);
return Response.ok(AwsQueryResponse.envelope("CreateDBInstance", AwsNamespaces.RDS, result)).build();
} catch (AwsException e) {
@@ -929,6 +934,8 @@ public class RdsQueryHandler {
}
try {
DbInstanceSettings settings = instanceSettings(params, false);
Integer promotionTier = parseIntegerParam(params, "PromotionTier");
RdsService.validatePromotionTier(promotionTier);
DbInstanceScalingChanges scaling = scalingChanges(params);
List<String> vpcSecurityGroupIds = vpcSecurityGroupIds(params);
DbInstance instance = service.modifyDbInstance(
@@ -936,6 +943,9 @@ public class RdsQueryHandler {
vpcSecurityGroupIds, optionGroupName, region, autoMinorVersionUpgrade,
settings, publiclyAccessible, scaling, deletionProtection,
params.getFirst("DBParameterGroupName"));
if (promotionTier != null) {
instance = service.setInstancePromotionTier(region, id, promotionTier);
}
String result = dbInstanceXml(instance);
return Response.ok(AwsQueryResponse.envelope("ModifyDBInstance", AwsNamespaces.RDS, result)).build();
} catch (AwsException e) {
@@ -1429,6 +1439,8 @@ public class RdsQueryHandler {
}
try {
Boolean copyTagsToSnapshot = parseOptionalBoolean(params, "CopyTagsToSnapshot");
List<String> exports = cloudwatchLogsExports(params);
List<DbRoleAssociation> associatedRoles = parseAssociatedRoles(params);
service.validateClusterRoleAssociations(id, engine, associatedRoles);
boolean enableHttpEndpoint = Boolean.TRUE.equals(parseOptionalBoolean(params, "EnableHttpEndpoint"));
@@ -1495,6 +1507,9 @@ public class RdsQueryHandler {
if (backupRetentionPeriodParam != null) {
cluster = service.setBackupRetentionPeriod(region, id, backupRetentionPeriod);
}
if (copyTagsToSnapshot != null || exports != null) {
cluster = service.setClusterSnapshotAndLogSettings(region, id, copyTagsToSnapshot, exports, null);
}
String result = dbClusterXml(cluster);
return Response.ok(AwsQueryResponse.envelope("CreateDBCluster", AwsNamespaces.RDS, result)).build();
} catch (AwsException e) {
@@ -1600,6 +1615,8 @@ public class RdsQueryHandler {
Boolean manageMasterUserPassword = manageStr != null ? Boolean.parseBoolean(manageStr) : null;
String masterUserSecretKmsKeyId = params.getFirst("MasterUserSecretKmsKeyId");
try {
Boolean copyTagsToSnapshot = parseOptionalBoolean(params, "CopyTagsToSnapshot");
LogExportChanges exportChanges = cloudwatchLogsExportChanges(params);
Double serverlessV2Min = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MinCapacity");
Double serverlessV2Max = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MaxCapacity");
Integer serverlessV2SecondsUntilAutoPause = parseIntegerParam(
@@ -1624,6 +1641,9 @@ public class RdsQueryHandler {
if (modifyBackupRetentionPeriod != null) {
cluster = service.setBackupRetentionPeriod(region, id, modifyBackupRetentionPeriod);
}
if (copyTagsToSnapshot != null || exportChanges != null) {
cluster = service.setClusterSnapshotAndLogSettings(region, id, copyTagsToSnapshot, null, exportChanges);
}
String result = dbClusterXml(cluster);
return Response.ok(AwsQueryResponse.envelope("ModifyDBCluster", AwsNamespaces.RDS, result)).build();
} catch (AwsException e) {
@@ -3435,7 +3455,8 @@ public class RdsQueryHandler {
xml.end("MasterUserSecret");
}
if (i.getDbClusterIdentifier() != null && !i.getDbClusterIdentifier().isBlank()) {
xml.elem("DBClusterIdentifier", i.getDbClusterIdentifier());
xml.elem("DBClusterIdentifier", i.getDbClusterIdentifier())
.elem("PromotionTier", i.getPromotionTier());
}
xml.raw(readReplicaXml(i));
writeAssociatedRoles(xml, i.getAssociatedRoles(), "DBInstanceRole");
@@ -3629,6 +3650,7 @@ public class RdsQueryHandler {
.elem("MultiAZ", c.isMultiAz())
.elem("StorageEncrypted", c.isStorageEncrypted())
.elem("BackupRetentionPeriod", c.getBackupRetentionPeriod())
.elem("CopyTagsToSnapshot", c.isCopyTagsToSnapshot())
.elem("KmsKeyId", c.getKmsKeyId())
.elem("AvailabilityZone", c.getAvailabilityZone() != null ? c.getAvailabilityZone() : config.defaultAvailabilityZone())
.elem("PreferredMaintenanceWindow", "mon:00:00-mon:03:00")
@@ -3671,6 +3693,11 @@ public class RdsQueryHandler {
if (c.getGlobalClusterIdentifier() != null && !c.getGlobalClusterIdentifier().isBlank()) {
xml.elem("GlobalClusterIdentifier", c.getGlobalClusterIdentifier());
}
if (c.getEnabledCloudwatchLogsExports() != null && !c.getEnabledCloudwatchLogsExports().isEmpty()) {
xml.start("EnabledCloudwatchLogsExports");
c.getEnabledCloudwatchLogsExports().forEach(type -> xml.elem("member", type));
xml.end("EnabledCloudwatchLogsExports");
}
xml.start("DBClusterMembers");
if (c.getDbClusterMembers() != null) {
String writer = c.resolveWriterIdentifier();
@@ -3678,6 +3705,7 @@ public class RdsQueryHandler {
xml.start("member")
.elem("DBInstanceIdentifier", memberId)
.elem("IsClusterWriter", memberId.equals(writer))
.elem("PromotionTier", service.clusterMemberPromotionTier(c, memberId))
.end("member");
}
}
@@ -60,6 +60,7 @@ import io.floci.aws.services.rds.model.DbSubnetGroup;
import io.floci.aws.services.rds.model.EventSubscription;
import io.floci.aws.services.rds.model.GlobalCluster;
import io.floci.aws.services.rds.model.GlobalClusterMember;
import io.floci.aws.services.rds.model.LogExportChanges;
import io.floci.aws.services.rds.model.OptionGroup;
import io.floci.aws.services.rds.model.OptionGroupOption;
import io.floci.aws.services.rds.model.PointInTimeRestoreRequest;
@@ -11946,6 +11947,45 @@ public class RdsService implements Resettable, ResourceProvider {
cluster.getDbClusterIdentifier());
return RESPONSE_COPIER.convertValue(cluster, DbCluster.class);
}
public synchronized DbCluster setClusterSnapshotAndLogSettings(String region, String clusterId,
Boolean copyTagsToSnapshot, List<String> exports, LogExportChanges changes) {
String effectiveRegion = effectiveRegion(region);
DbCluster cluster = getDbCluster(clusterId, effectiveRegion);
if (copyTagsToSnapshot != null) {
cluster.setCopyTagsToSnapshot(copyTagsToSnapshot);
}
if (exports != null) {
cluster.setEnabledCloudwatchLogsExports(exports);
}
if (changes != null) {
cluster.setEnabledCloudwatchLogsExports(changes.applyTo(cluster.getEnabledCloudwatchLogsExports()));
}
putClusterForScope(currentAccountId(), effectiveRegion, cluster.getDbClusterIdentifier(), cluster);
return RESPONSE_COPIER.convertValue(cluster, DbCluster.class);
}
public static void validatePromotionTier(Integer tier) {
if (tier != null && (tier < 0 || tier > 15)) {
throw new AwsException("InvalidParameterValue", "PromotionTier must be between 0 and 15.", 400);
}
}
public synchronized DbInstance setInstancePromotionTier(String region, String instanceId, int tier) {
validatePromotionTier(tier);
String effectiveRegion = effectiveRegion(region);
DbInstance instance = getDbInstance(instanceId, effectiveRegion);
instance.setPromotionTier(tier);
putInstanceForScope(currentAccountId(), effectiveRegion, instance.getDbInstanceIdentifier(), instance);
return RESPONSE_COPIER.convertValue(instance, DbInstance.class);
}
public int clusterMemberPromotionTier(DbCluster cluster, String memberId) {
DbInstance member = findInstanceForScope(accountIdFromArn(cluster.getDbClusterArn()),
AwsArnUtils.regionOrDefault(cluster.getDbClusterArn(), regionResolver.getDefaultRegion()), memberId);
return member == null ? 1 : member.getPromotionTier();
}
private static final Set<String> DATA_API_ENGINES = Set.of("aurora-postgresql", "aurora-mysql");
/**
@@ -48,6 +48,8 @@ public class DbCluster {
private String engineMode;
private boolean storageEncrypted;
private int backupRetentionPeriod = 1;
private boolean copyTagsToSnapshot;
private List<String> enabledCloudwatchLogsExports = new ArrayList<>();
private String kmsKeyId;
private String dockerVolumeName;
@@ -253,4 +255,11 @@ public class DbCluster {
public void setServerlessV2SecondsUntilAutoPause(Integer serverlessV2SecondsUntilAutoPause) {
this.serverlessV2SecondsUntilAutoPause = serverlessV2SecondsUntilAutoPause;
}
public boolean isCopyTagsToSnapshot() { return copyTagsToSnapshot; }
public void setCopyTagsToSnapshot(boolean value) { copyTagsToSnapshot = value; }
public List<String> getEnabledCloudwatchLogsExports() { return enabledCloudwatchLogsExports; }
public void setEnabledCloudwatchLogsExports(List<String> value) {
enabledCloudwatchLogsExports = value == null ? new ArrayList<>() : new ArrayList<>(value);
}
}
@@ -52,6 +52,7 @@ public class DbInstance {
private String preferredBackupWindow;
private String preferredMaintenanceWindow;
private boolean copyTagsToSnapshot;
private int promotionTier = 1;
private boolean deletionProtection;
private boolean publiclyAccessible;
/** MonitoringInterval documents 0 as its default. */
@@ -357,4 +358,7 @@ public class DbInstance {
public void setMaxAllocatedStorage(Integer maxAllocatedStorage) {
this.maxAllocatedStorage = maxAllocatedStorage;
}
public int getPromotionTier() { return promotionTier; }
public void setPromotionTier(int value) { promotionTier = value; }
}