fix(cloudformation): delete a renamed RDS DB instance in the stack's region (#9567)

Renaming an AWS::RDS::DBInstance created the new instance in the stack's Region but deleted the old one through the Region-less deleteDbInstance, which uses the default Region. A stack outside the default Region left its old instance behind, and could delete a same-named instance in the default Region. The delete now passes the stack's Region.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-11-26 20:27:34 -04:00
1 parent 613ace44dc
commit febdf59f2d
2 files changed
+17 -1

No files matched your search

@@ -486,7 +486,8 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
instance = reconcileInstanceRoles(r, instance, roles, created, region);
ASSOCIATED_ROLES.record(r, ctx, attributesBefore, associatedRolesRecord(roles));
if (created && !replacing) {
deleteRenamedResource(priorPhysicalId, id, rdsService::deleteDbInstance, "DB instance");
deleteRenamedResource(priorPhysicalId, id, oldId -> rdsService.deleteDbInstance(oldId, region),
"DB instance");
}
r.setPhysicalId(instance.getDbInstanceIdentifier());
r.getAttributes().put("DBInstanceIdentifier", instance.getDbInstanceIdentifier());
@@ -1730,6 +1730,21 @@ class RdsCfnProvisionerTest {
verify(rdsService, never()).deleteDbInstance("olddb", "us-east-1");
}
@Test
void renamedDbInstanceDeletesItsPredecessorInTheStackRegion() {
stubCreatedInstance("newdb");
StackResource r = provisionExisting("Db", "AWS::RDS::DBInstance", """
{"DBInstanceIdentifier":"newdb","Engine":"postgres","MasterUsername":"admin",
"MasterUserPassword":"secret"}
""", "eu-west-1", "olddb", Map.of("DBInstanceIdentifier", "olddb"));
assertEquals("newdb", r.getPhysicalId());
verify(rdsService).deleteDbInstance("olddb", "eu-west-1");
verify(rdsService, never()).deleteDbInstance("olddb", "us-east-1");
verify(rdsService, never()).deleteDbInstance("olddb");
}
@Test
void failedLaterUpdateRollsBackDbClusterReplacementToThePriorCluster() {
// A later resource failing the stack update rolls the replacement back: the resource names