fix(cloudformation): delete a renamed RDS DB subnet group in the stack's region (#9620)

Renaming an AWS::RDS::DBSubnetGroup created the new group in the stack's
Region but deleted the old one through the region-less overload, which
uses the default Region. A stack outside the default Region left its old
group behind and could delete a same-named group in the default Region.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-11-27 18:18:43 -04:00
1 parent f06f1e7fd8
commit a2d37a4cc5
2 files changed
+19 -1

No files matched your search

@@ -309,7 +309,7 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
group = rdsService.modifyDbSubnetGroup(name, subnetIds, region);
} else {
group = rdsService.createDbSubnetGroup(name, description, subnetIds, region);
deleteRenamedResource(priorPhysicalId, name, id -> rdsService.deleteDbSubnetGroup(id), "DB subnet group");
deleteRenamedResource(priorPhysicalId, name, id -> rdsService.deleteDbSubnetGroup(id, region), "DB subnet group");
}
r.setPhysicalId(group.getDbSubnetGroupName());
r.getAttributes().put("DBSubnetGroupName", group.getDbSubnetGroupName());
@@ -1094,6 +1094,24 @@ class RdsCfnProvisionerTest {
List.of("subnet-a"), "us-west-2");
}
@Test
void renamedDbSubnetGroupDeletesItsPredecessorInTheStackRegion() {
DbSubnetGroup group = mock(DbSubnetGroup.class);
when(group.getDbSubnetGroupName()).thenReturn("new-subnets");
when(rdsService.createDbSubnetGroup(any(), any(), anyList(), any())).thenReturn(group);
StackResource r = provisionExisting("Sg", "AWS::RDS::DBSubnetGroup", """
{"DBSubnetGroupName":"new-subnets","SubnetIds":["subnet-a"]}
""", "eu-west-1", "old-subnets", Map.of());
assertEquals("new-subnets", r.getPhysicalId());
verify(rdsService).createDbSubnetGroup("new-subnets", "Managed by CloudFormation",
List.of("subnet-a"), "eu-west-1");
verify(rdsService).deleteDbSubnetGroup("old-subnets", "eu-west-1");
verify(rdsService, never()).deleteDbSubnetGroup("old-subnets", "us-east-1");
verify(rdsService, never()).deleteDbSubnetGroup("old-subnets");
}
/**
* Repro for issue #2937: a CDK cross-stack VPC exposes its subnet ids as one comma-joined
* export, so the consuming stack passes {@code SubnetIds} as a list-valued intrinsic