mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(rds): honor DeletionProtection on cluster restores and AWS::RDS::DBCluster (#9057)
RestoreDBClusterFromSnapshot and RestoreDBClusterToPointInTime now read DeletionProtection and set it on the new cluster before it is stored. The AWS::RDS::DBCluster provisioner reads DeletionProtection, creates the cluster with it, and applies a changed value on stack update. A stack delete of a protected cluster is refused by DeleteDBCluster and reported as the resource's DELETE_FAILED, as on AWS. A restore, or a CloudFormation role attach, that fails after creating the cluster goes through one cleanup that clears the flag and always attempts the delete, adding any failure to the original error. Closes #9056
This commit is contained in:
1 parent
3e1fe3c8b6
commit
3f51fdec34
10 files changed
+218
-82
No files matched your search
@@ -238,6 +238,8 @@ checked against the instance's other window. Modifications apply immediately —
|
||||
and the enabled CloudWatch log export types. Modify uses `CloudwatchLogsExportConfiguration`
|
||||
enable and disable deltas; omitted fields preserve their values, including an explicit
|
||||
false snapshot-copy flag. Create, modify and describe return the stored settings.
|
||||
`RestoreDBClusterFromSnapshot` and `RestoreDBClusterToPointInTime` also set `DeletionProtection`
|
||||
on the new cluster, defaulting to false.
|
||||
|
||||
Aurora member instances retain `PromotionTier` from create and modify, defaulting
|
||||
to 1 and accepting 0 through 15. Both the instance response and the cluster member
|
||||
|
||||
+6
-3
@@ -655,6 +655,7 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
|
||||
// Refused before a new cluster exists, rather than leaving one behind.
|
||||
RdsService.requireDataApiEngine(resolveOptional(props, "Engine", engine));
|
||||
}
|
||||
boolean deletionProtection = parseStrictBoolProp(props, "DeletionProtection", engine);
|
||||
boolean created = cluster == null;
|
||||
if (cluster != null) {
|
||||
cluster = rdsService.modifyDbCluster(
|
||||
@@ -680,7 +681,7 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
|
||||
cluster = rdsService.createDbCluster(id, engineName, engineVersion, masterUsername,
|
||||
masterPassword, databaseName, iamEnabled, parameterGroup, null, null, false, region,
|
||||
serverlessV2MinCapacity, serverlessV2MaxCapacity, serverlessV2SecondsUntilAutoPause,
|
||||
false, null, engineMode, storageEncrypted);
|
||||
false, null, engineMode, storageEncrypted, null, deletionProtection);
|
||||
}
|
||||
cluster = reconcileClusterRoles(r, cluster, roles, created, region);
|
||||
ASSOCIATED_ROLES.record(r, ctx, attributesBefore, associatedRolesRecord(roles));
|
||||
@@ -688,6 +689,9 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
|
||||
if (httpEndpoint != cluster.isHttpEndpointEnabled()) {
|
||||
cluster = rdsService.setHttpEndpoint(region, cluster.getDbClusterIdentifier(), httpEndpoint);
|
||||
}
|
||||
if (deletionProtection != cluster.isDeletionProtection()) {
|
||||
cluster = rdsService.setDeletionProtection(region, cluster.getDbClusterIdentifier(), deletionProtection);
|
||||
}
|
||||
r.setPhysicalId(cluster.getDbClusterIdentifier());
|
||||
r.getAttributes().put("DBClusterIdentifier", cluster.getDbClusterIdentifier());
|
||||
if (cluster.getEndpoint() != null) {
|
||||
@@ -758,8 +762,7 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
|
||||
try {
|
||||
cluster = rdsService.addRolesToNewDbCluster(region, id, roles);
|
||||
} catch (AwsException e) {
|
||||
CfnDeletes.safeDelete("DB cluster", id, () -> rdsService.deleteDbCluster(id, region),
|
||||
"DBClusterNotFoundFault");
|
||||
rdsService.discardCreatedCluster(region, id, cluster.isDeletionProtection(), e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3059,7 +3059,9 @@ public class RdsQueryHandler {
|
||||
optionalInt(params.getFirst("Port")), params.getFirst("DBSubnetGroupName"),
|
||||
params.getFirst("DBClusterParameterGroupName"),
|
||||
parseOptionalBoolean(params, "EnableIAMDatabaseAuthentication"),
|
||||
params.getFirst("EngineMode"), parseTags(params), region);
|
||||
params.getFirst("EngineMode"),
|
||||
Boolean.TRUE.equals(parseOptionalBoolean(params, "DeletionProtection")),
|
||||
parseTags(params), region);
|
||||
return Response.ok(AwsQueryResponse.envelope("RestoreDBClusterToPointInTime", AwsNamespaces.RDS,
|
||||
dbClusterXml(cluster))).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -3084,7 +3086,9 @@ public class RdsQueryHandler {
|
||||
params.getFirst("DBClusterParameterGroupName"),
|
||||
params.getFirst("AvailabilityZones.member.1"),
|
||||
parseOptionalBoolean(params, "EnableIAMDatabaseAuthentication"),
|
||||
params.getFirst("EngineMode"), parseTags(params), region);
|
||||
params.getFirst("EngineMode"),
|
||||
Boolean.TRUE.equals(parseOptionalBoolean(params, "DeletionProtection")),
|
||||
parseTags(params), region);
|
||||
return Response.ok(AwsQueryResponse.envelope("RestoreDBClusterFromSnapshot", AwsNamespaces.RDS,
|
||||
dbClusterXml(cluster))).build();
|
||||
}
|
||||
|
||||
@@ -2772,7 +2772,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
String engineVersion, Integer port, String databaseName,
|
||||
String dbSubnetGroupName, String parameterGroupName,
|
||||
String availabilityZone, Boolean iamEnabled, String engineMode,
|
||||
Map<String, String> tags, String region) {
|
||||
boolean deletionProtection, Map<String, String> tags,
|
||||
String region) {
|
||||
String effectiveRegion = effectiveRegion(region);
|
||||
String accountId = currentAccountId();
|
||||
// SnapshotIdentifier takes the snapshot's name or its ARN (API reference).
|
||||
@@ -2798,7 +2799,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
parameterGroupName, dbSubnetGroupName, availabilityZone, false, effectiveRegion,
|
||||
null, null, null, false, null,
|
||||
engineMode != null && !engineMode.isBlank() ? engineMode : snapshot.getEngineMode(),
|
||||
snapshot.isStorageEncrypted(), port, false);
|
||||
snapshot.isStorageEncrypted(), port, deletionProtection);
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
cluster.getTags().putAll(tags);
|
||||
putClusterForScope(accountId, effectiveRegion, clusterId, cluster);
|
||||
@@ -2807,11 +2808,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
try {
|
||||
containerManager.restorePostgresSnapshot(cluster.getContainerId(), cluster.getMasterUsername(), sqlDump);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
deleteDbCluster(clusterId, effectiveRegion);
|
||||
} catch (Exception cleanupError) {
|
||||
e.addSuppressed(cleanupError);
|
||||
}
|
||||
discardCreatedCluster(effectiveRegion, clusterId, deletionProtection, e);
|
||||
AwsException awsEx = new AwsException("InvalidDBClusterSnapshotStateFault",
|
||||
"Failed to restore snapshot: " + e.getMessage(), 400);
|
||||
awsEx.initCause(e);
|
||||
@@ -2832,7 +2829,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
String sourceClusterResourceId, String restoreType,
|
||||
Instant restoreToTime, Boolean useLatestRestorableTime,
|
||||
Integer port, String dbSubnetGroupName, String parameterGroupName,
|
||||
Boolean iamEnabled, String engineMode,
|
||||
Boolean iamEnabled, String engineMode, boolean deletionProtection,
|
||||
Map<String, String> tags, String region) {
|
||||
String effectiveRegion = effectiveRegion(region);
|
||||
String accountId = currentAccountId();
|
||||
@@ -2897,7 +2894,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
parameterGroupName, dbSubnetGroupName, null, false, effectiveRegion,
|
||||
null, null, null, false, null,
|
||||
!isBlank(engineMode) ? engineMode : source.getEngineMode(),
|
||||
source.isStorageEncrypted(), port, false);
|
||||
source.isStorageEncrypted(), port, deletionProtection);
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
cluster.getTags().putAll(tags);
|
||||
putClusterForScope(accountId, effectiveRegion, clusterId, cluster);
|
||||
@@ -2916,11 +2913,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
containerManager.restorePostgresSnapshot(
|
||||
cluster.getContainerId(), cluster.getMasterUsername(), sqlDump);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
deleteDbCluster(clusterId, effectiveRegion);
|
||||
} catch (Exception cleanupError) {
|
||||
e.addSuppressed(cleanupError);
|
||||
}
|
||||
discardCreatedCluster(effectiveRegion, clusterId, deletionProtection, e);
|
||||
AwsException failure = new AwsException("InvalidDBClusterStateFault",
|
||||
"Failed to restore DB cluster " + sourceId + " to " + clusterId + ": "
|
||||
+ e.getMessage(), 400);
|
||||
@@ -2932,6 +2925,21 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
return cluster;
|
||||
}
|
||||
|
||||
public void discardCreatedCluster(String region, String clusterId, boolean deletionProtection, Exception cause) {
|
||||
if (deletionProtection) {
|
||||
try {
|
||||
setDeletionProtection(region, clusterId, false);
|
||||
} catch (Exception unprotectError) {
|
||||
cause.addSuppressed(unprotectError);
|
||||
}
|
||||
}
|
||||
try {
|
||||
deleteDbCluster(clusterId, region);
|
||||
} catch (Exception deleteError) {
|
||||
cause.addSuppressed(deleteError);
|
||||
}
|
||||
}
|
||||
|
||||
private DbClusterSnapshot clusterSnapshotOf(DbCluster cluster, String snapshotId, String region) {
|
||||
DbClusterSnapshot snapshot = new DbClusterSnapshot();
|
||||
snapshot.setDbClusterSnapshotIdentifier(snapshotId);
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package io.floci.aws.services.cloudformation;
|
||||
|
||||
import io.floci.aws.testing.CfnStackWaits;
|
||||
import io.floci.aws.testing.RdsMockProfile;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.floci.aws.testing.CfnRequests.cfn;
|
||||
import static io.floci.aws.testing.CfnRequests.deploy;
|
||||
import static io.floci.aws.testing.RdsRequests.rds;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@QuarkusTest
|
||||
@TestProfile(RdsMockProfile.class)
|
||||
class CloudFormationRdsDeletionProtectionIntegrationTest {
|
||||
|
||||
private static final String CFN_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20261119/us-east-1/cloudformation/aws4_request";
|
||||
|
||||
private static String template(String clusterId, String deletionProtection) {
|
||||
return """
|
||||
{"Resources": {"Cluster": {"Type": "AWS::RDS::DBCluster", "Properties": {
|
||||
"DBClusterIdentifier": "%s", "Engine": "aurora-postgresql",
|
||||
"MasterUsername": "dbadmin", "MasterUserPassword": "password123",
|
||||
"DeletionProtection": "%s"}}}}
|
||||
""".formatted(clusterId, deletionProtection);
|
||||
}
|
||||
|
||||
private static void describeReports(String clusterId, String expected) {
|
||||
rds("DescribeDBClusters").formParam("DBClusterIdentifier", clusterId)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<DeletionProtection>" + expected + "</DeletionProtection>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void stackClusterFollowsDeletionProtectionAndRefusesStackDeleteWhileProtected() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "cfn-rds-dp-" + suffix;
|
||||
String clusterId = "cfn-dp-cluster-" + suffix;
|
||||
try {
|
||||
deploy("CreateStack", stackName, template(clusterId, "true"), CFN_AUTH, "CREATE_COMPLETE");
|
||||
describeReports(clusterId, "true");
|
||||
|
||||
deploy("UpdateStack", stackName, template(clusterId, "false"), CFN_AUTH, "UPDATE_COMPLETE");
|
||||
describeReports(clusterId, "false");
|
||||
deploy("UpdateStack", stackName, template(clusterId, "true"), CFN_AUTH, "UPDATE_COMPLETE");
|
||||
describeReports(clusterId, "true");
|
||||
|
||||
cfn("DeleteStack", stackName).header("Authorization", CFN_AUTH)
|
||||
.when().post("/").then().statusCode(200);
|
||||
assertEquals("DELETE_FAILED", CfnStackWaits.awaitTerminal(stackName, CFN_AUTH).status());
|
||||
describeReports(clusterId, "true");
|
||||
} finally {
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", clusterId)
|
||||
.formParam("DeletionProtection", "false").when().post("/");
|
||||
CfnStackWaits.deleteStack(stackName, CFN_AUTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getDbClusterResourceId()).thenReturn("cluster-ABCDEFGHIJKLMNOP");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
StackResource r = provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
@@ -289,7 +289,7 @@ class RdsCfnProvisionerTest {
|
||||
assertEquals("cluster-ABCDEFGHIJKLMNOP", r.getAttributes().get("DBClusterResourceId"));
|
||||
verify(rdsService).createDbCluster("mycluster", "aurora-postgresql", "16.3",
|
||||
"admin", "secret", "appdb", false, null, null, null, false, "us-east-1",
|
||||
null, null, null, false, null, null, false);
|
||||
null, null, null, false, null, null, false, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -344,7 +344,7 @@ class RdsCfnProvisionerTest {
|
||||
assertEquals("CREATE_FAILED", r.getStatus());
|
||||
assertTrue(r.getStatusReason().contains("Aurora"), r.getStatusReason());
|
||||
verify(rdsService, never()).createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(), anyBoolean());
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -353,7 +353,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
@@ -362,7 +362,7 @@ class RdsCfnProvisionerTest {
|
||||
|
||||
verify(rdsService).createDbCluster("mycluster", "aurora-postgresql", null,
|
||||
null, null, null, false, null, null, null, false, "us-west-2",
|
||||
null, null, null, false, null, null, false);
|
||||
null, null, null, false, null, null, false, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -371,7 +371,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
@@ -382,7 +382,7 @@ class RdsCfnProvisionerTest {
|
||||
|
||||
verify(rdsService).createDbCluster("mycluster", "aurora-postgresql", null,
|
||||
null, null, null, false, null, null, null, false, "us-east-1",
|
||||
0.0, 16.0, 600, false, null, null, false);
|
||||
0.0, 16.0, 600, false, null, null, false, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -391,7 +391,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
@@ -401,7 +401,7 @@ class RdsCfnProvisionerTest {
|
||||
|
||||
verify(rdsService).createDbCluster("mycluster", "aurora-postgresql", null,
|
||||
null, null, null, false, null, null, null, false, "us-east-1",
|
||||
null, null, null, false, null, "serverless", true);
|
||||
null, null, null, false, null, "serverless", true, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -440,7 +440,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getEndpoint()).thenReturn(new DbEndpoint("mycluster.local", 5432));
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
@@ -453,7 +453,7 @@ class RdsCfnProvisionerTest {
|
||||
verify(rdsService).createDbCluster(eq("mycluster"), eq("aurora-postgresql"), eq("16.3"),
|
||||
eq("resolved-user"), eq("resolved-secret"), eq("appdb"), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(),
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean());
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
verify(secretsManagerService, times(2))
|
||||
.getSecretValue("my-secret", null, null, "us-west-2");
|
||||
}
|
||||
@@ -492,7 +492,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
@@ -505,7 +505,7 @@ class RdsCfnProvisionerTest {
|
||||
eq("mycluster"), eq("aurora-postgresql"), any(), eq("admin"),
|
||||
eq("resolved-secret"), any(), anyBoolean(), any(), any(), any(),
|
||||
anyBoolean(), eq("us-east-1"),
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean());
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
verify(secretsManagerService)
|
||||
.getSecretValue("my-secret", null, null, "us-east-1");
|
||||
}
|
||||
@@ -520,7 +520,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
String secretArn =
|
||||
@@ -535,7 +535,7 @@ class RdsCfnProvisionerTest {
|
||||
eq("mycluster"), eq("aurora-postgresql"), any(), eq("admin"),
|
||||
eq("resolved-secret"), any(), anyBoolean(), any(), any(), any(),
|
||||
anyBoolean(), eq("us-east-1"),
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean());
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
verify(secretsManagerService)
|
||||
.getSecretValue(secretArn, null, null, "us-west-2");
|
||||
}
|
||||
@@ -550,7 +550,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
String secretArn =
|
||||
@@ -565,7 +565,7 @@ class RdsCfnProvisionerTest {
|
||||
eq("mycluster"), eq("aurora-postgresql"), any(), eq("admin"),
|
||||
eq("resolved-secret"), any(), anyBoolean(), any(), any(), any(),
|
||||
anyBoolean(), eq("us-east-1"),
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean());
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
verify(secretsManagerService)
|
||||
.getSecretValue(secretArn, null, null, "us-west-2");
|
||||
}
|
||||
@@ -580,7 +580,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
String secretArn =
|
||||
@@ -595,7 +595,7 @@ class RdsCfnProvisionerTest {
|
||||
eq("mycluster"), eq("aurora-postgresql"), any(), eq("admin"),
|
||||
eq("resolved-secret"), any(), anyBoolean(), any(), any(), any(),
|
||||
anyBoolean(), eq("us-east-1"),
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean());
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
verify(secretsManagerService)
|
||||
.getSecretValue(secretArn, null, null, "us-west-2");
|
||||
}
|
||||
@@ -676,7 +676,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getEndpoint()).thenReturn(new DbEndpoint("mycluster.local", 5432));
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
@@ -690,7 +690,7 @@ class RdsCfnProvisionerTest {
|
||||
verify(rdsService).createDbCluster(eq("mycluster"), eq("aurora-postgresql"), eq("16.3"),
|
||||
eq("admin"), eq("resolved-ssm"), eq("appdb"), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(),
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean());
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -702,7 +702,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
StackResource resource = provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
@@ -715,7 +715,7 @@ class RdsCfnProvisionerTest {
|
||||
verify(rdsService).createDbCluster(eq("mycluster"), eq("aurora-postgresql"), any(),
|
||||
eq("resolved-user"), eq("secret"), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), eq("us-east-1"),
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean());
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -727,7 +727,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
StackResource resource = provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
@@ -740,7 +740,7 @@ class RdsCfnProvisionerTest {
|
||||
verify(rdsService).createDbCluster(eq("mycluster"), eq("aurora-postgresql"), any(),
|
||||
eq("admin"), eq("first,second"), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), eq("us-east-1"),
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean());
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -830,7 +830,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
StackResource resource = provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
@@ -843,7 +843,7 @@ class RdsCfnProvisionerTest {
|
||||
verify(rdsService).createDbCluster(eq("mycluster"), eq("aurora-postgresql"), any(),
|
||||
eq("admin"), eq("first-password"), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), eq("us-west-2"),
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean());
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
verify(ssmService, never()).getParameter(any(), any());
|
||||
}
|
||||
|
||||
@@ -860,7 +860,7 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
StackResource resource = provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
@@ -873,7 +873,7 @@ class RdsCfnProvisionerTest {
|
||||
verify(rdsService).createDbCluster(eq("mycluster"), eq("aurora-postgresql"), any(),
|
||||
eq("admin"), eq("first-password"), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), eq("us-west-2"),
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean());
|
||||
any(), any(), any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
verify(ssmService, never()).getParameter(any(), any());
|
||||
}
|
||||
|
||||
@@ -1478,7 +1478,7 @@ class RdsCfnProvisionerTest {
|
||||
assertEquals("mycluster", r.getPhysicalId());
|
||||
verify(rdsService, never()).createDbCluster(any(), any(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), any(), anyBoolean(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), anyBoolean());
|
||||
anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
verify(rdsService).modifyDbCluster("mycluster", "secret", false,
|
||||
null, null, null, "us-east-1");
|
||||
}
|
||||
@@ -1494,7 +1494,7 @@ class RdsCfnProvisionerTest {
|
||||
};
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean())).thenAnswer(echo);
|
||||
anyBoolean(), any(), anyBoolean())).thenAnswer(echo);
|
||||
}
|
||||
|
||||
/** The unnamed cluster a previous CreateStack left on file under a generated physical id. */
|
||||
@@ -1531,7 +1531,7 @@ class RdsCfnProvisionerTest {
|
||||
assertEquals(replacement, r.getAttributes().get("DBClusterIdentifier"));
|
||||
verify(rdsService).createDbCluster(replacement, "aurora-postgresql", null,
|
||||
"admin", "secret", null, false, null, null, null, false, "us-east-1",
|
||||
null, null, null, false, null, "serverless", false);
|
||||
null, null, null, false, null, "serverless", false, null, false);
|
||||
verify(rdsService, never()).modifyDbCluster(any(), any(), any(), any(), any(), any(), any());
|
||||
verify(rdsService, never()).deleteDbCluster(any(), any());
|
||||
|
||||
@@ -1544,7 +1544,7 @@ class RdsCfnProvisionerTest {
|
||||
InOrder inOrder = inOrder(rdsService);
|
||||
inOrder.verify(rdsService).createDbCluster(eq(replacement), any(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), any(), anyBoolean(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), anyBoolean());
|
||||
anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
inOrder.verify(rdsService).deleteDbCluster(PRIOR_CLUSTER, "us-east-1");
|
||||
verify(rdsService, never()).deleteDbCluster(replacement, "us-east-1");
|
||||
provisioner.clearUpdate(r);
|
||||
@@ -1565,7 +1565,7 @@ class RdsCfnProvisionerTest {
|
||||
assertNotEquals(PRIOR_CLUSTER, replacement);
|
||||
verify(rdsService).createDbCluster(replacement, "aurora-postgresql", null,
|
||||
null, null, null, false, null, null, null, false, "us-east-1",
|
||||
null, null, null, false, null, null, true);
|
||||
null, null, null, false, null, null, true, null, false);
|
||||
verify(rdsService, never()).modifyDbCluster(any(), any(), any(), any(), any(), any(), any());
|
||||
assertEquals(PRIOR_CLUSTER, provisioner.updateCleanupPhysicalId(r));
|
||||
verify(rdsService, never()).deleteDbCluster(any(), any());
|
||||
@@ -1579,7 +1579,7 @@ class RdsCfnProvisionerTest {
|
||||
priorUnnamedCluster("provisioned", false);
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean()))
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenThrow(new AwsException("InvalidParameterCombination",
|
||||
"The engine mode serverless is not supported for aurora-postgresql 16.3.", 400));
|
||||
|
||||
@@ -1759,7 +1759,7 @@ class RdsCfnProvisionerTest {
|
||||
verify(rdsService, never()).modifyDbCluster(any(), any(), any(), any(), any(), any(), any());
|
||||
verify(rdsService, never()).createDbCluster(any(), any(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), any(), anyBoolean(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), anyBoolean());
|
||||
anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1802,7 +1802,7 @@ class RdsCfnProvisionerTest {
|
||||
verify(rdsService, never()).deleteDbCluster(any(), any());
|
||||
verify(rdsService, never()).createDbCluster(any(), any(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), any(), anyBoolean(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), anyBoolean());
|
||||
anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
verify(rdsService).modifyDbCluster("mycluster", "rotated", false,
|
||||
null, null, null, "us-east-1");
|
||||
}
|
||||
@@ -1879,7 +1879,7 @@ class RdsCfnProvisionerTest {
|
||||
assertNotEquals(PRIOR_CLUSTER, replacement);
|
||||
verify(rdsService).createDbCluster(replacement, "aurora-postgresql", null, null, null,
|
||||
"reports", false, null, null, null, false, "us-east-1",
|
||||
null, null, null, false, null, null, false);
|
||||
null, null, null, false, null, null, false, null, false);
|
||||
verify(rdsService, never()).modifyDbCluster(any(), any(), any(), any(), any(), any(), any());
|
||||
verify(rdsService, never()).deleteDbCluster(any(), any());
|
||||
assertEquals(PRIOR_CLUSTER, provisioner.updateCleanupPhysicalId(r));
|
||||
@@ -1948,7 +1948,7 @@ class RdsCfnProvisionerTest {
|
||||
null, null, null, "us-east-1");
|
||||
verify(rdsService, times(1)).createDbCluster(any(), any(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), any(), anyBoolean(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), anyBoolean());
|
||||
anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
assertEquals(record, r.getAttributes().get(CREATE_ONLY_ATTR));
|
||||
assertFalse(r.getAttributes().containsKey(CREATE_ONLY_PRIOR_ATTR));
|
||||
assertFalse(provisioner.hasReplacementUpdate(r));
|
||||
@@ -2048,7 +2048,7 @@ class RdsCfnProvisionerTest {
|
||||
verify(rdsService).modifyDbCluster(prior, null, false, null, null, null, "us-east-1");
|
||||
verify(rdsService, times(2)).createDbCluster(any(), any(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), any(), anyBoolean(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), anyBoolean());
|
||||
anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+48
-5
@@ -17,13 +17,18 @@ import static org.hamcrest.Matchers.containsString;
|
||||
class RdsClusterDeletionProtectionIntegrationTest {
|
||||
|
||||
private static final String ID = "dp-cluster";
|
||||
private static final String RESTORED = "dp-restored";
|
||||
private static final String SNAPSHOT = "dp-snapshot";
|
||||
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("DeletionProtection", "false").when().post("/");
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("SkipFinalSnapshot", "true").when().post("/");
|
||||
for (String id : new String[]{RESTORED, ID}) {
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", id)
|
||||
.formParam("DeletionProtection", "false").when().post("/");
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", id)
|
||||
.formParam("SkipFinalSnapshot", "true").when().post("/");
|
||||
}
|
||||
rds("DeleteDBClusterSnapshot").formParam("DBClusterSnapshotIdentifier", SNAPSHOT).when().post("/");
|
||||
}
|
||||
|
||||
private static Response createCluster(String deletionProtection) {
|
||||
@@ -35,11 +40,29 @@ class RdsClusterDeletionProtectionIntegrationTest {
|
||||
}
|
||||
|
||||
private static void describeReports(String expected) {
|
||||
rds("DescribeDBClusters").formParam("DBClusterIdentifier", ID)
|
||||
describeReports(ID, expected);
|
||||
}
|
||||
|
||||
private static void describeReports(String id, String expected) {
|
||||
rds("DescribeDBClusters").formParam("DBClusterIdentifier", id)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<DeletionProtection>" + expected + "</DeletionProtection>"));
|
||||
}
|
||||
|
||||
private static void restoredIsProtected(RequestSpecification restore) {
|
||||
restore.formParam("DBClusterIdentifier", RESTORED)
|
||||
.formParam("DeletionProtection", "true")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<DeletionProtection>true</DeletionProtection>"));
|
||||
describeReports(RESTORED, "true");
|
||||
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", RESTORED)
|
||||
.formParam("SkipFinalSnapshot", "true")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterCombination</Code>"));
|
||||
describeReports(RESTORED, "true");
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletionProtectionDefaultsToFalse() {
|
||||
createCluster(null).then().statusCode(200)
|
||||
@@ -103,4 +126,24 @@ class RdsClusterDeletionProtectionIntegrationTest {
|
||||
.body(containsString("<DeletionProtection>true</DeletionProtection>"));
|
||||
describeReports("true");
|
||||
}
|
||||
|
||||
@Test
|
||||
void restoreFromSnapshotTakesDeletionProtection() {
|
||||
createCluster(null).then().statusCode(200);
|
||||
rds("CreateDBClusterSnapshot").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("DBClusterSnapshotIdentifier", SNAPSHOT).when().post("/").then().statusCode(200);
|
||||
|
||||
restoredIsProtected(rds("RestoreDBClusterFromSnapshot")
|
||||
.formParam("SnapshotIdentifier", SNAPSHOT)
|
||||
.formParam("Engine", "aurora-postgresql"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void restoreToPointInTimeTakesDeletionProtection() {
|
||||
createCluster(null).then().statusCode(200);
|
||||
|
||||
restoredIsProtected(rds("RestoreDBClusterToPointInTime")
|
||||
.formParam("SourceDBClusterIdentifier", ID)
|
||||
.formParam("UseLatestRestorableTime", "true"));
|
||||
}
|
||||
}
|
||||
@@ -2943,9 +2943,9 @@ class RdsQueryHandlerTest {
|
||||
when(service.restoreDbInstanceFromDbSnapshot(any(), any(), any(), any(), anyBoolean(),
|
||||
any(), any(), any(), any(), any(), any(), isNull(), isNull())).thenReturn(makeInstance("restored"));
|
||||
when(service.restoreDbClusterFromSnapshot(any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any(), any(), any(), any())).thenReturn(makeCluster("restored"));
|
||||
any(), any(), any(), any(), any(), anyBoolean(), any(), any())).thenReturn(makeCluster("restored"));
|
||||
when(service.restoreDbClusterToPointInTime(any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any(), any(), any(), any())).thenReturn(makeCluster("restored"));
|
||||
any(), any(), any(), any(), any(), anyBoolean(), any(), any())).thenReturn(makeCluster("restored"));
|
||||
for (String invalid : List.of("yes", "", "not-a-boolean")) {
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.putSingle("DBInstanceIdentifier", "restored");
|
||||
@@ -3022,10 +3022,10 @@ class RdsQueryHandlerTest {
|
||||
Boolean enabled = value == null ? null : Boolean.parseBoolean(value);
|
||||
when(service.restoreDbClusterFromSnapshot(eq("restored"), eq("snapshot"), eq("aurora-postgresql"),
|
||||
isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), eq(enabled), isNull(),
|
||||
eq(Map.of()), isNull())).thenReturn(makeCluster("restored"));
|
||||
eq(false), eq(Map.of()), isNull())).thenReturn(makeCluster("restored"));
|
||||
when(service.restoreDbClusterToPointInTime(eq("restored"), eq("source"), isNull(), isNull(),
|
||||
isNull(), eq(true), isNull(), isNull(), isNull(), eq(enabled), isNull(),
|
||||
eq(Map.of()), isNull())).thenReturn(makeCluster("restored"));
|
||||
eq(false), eq(Map.of()), isNull())).thenReturn(makeCluster("restored"));
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.putSingle("DBClusterIdentifier", "restored");
|
||||
p.putSingle("SnapshotIdentifier", "snapshot");
|
||||
@@ -3036,12 +3036,12 @@ class RdsQueryHandlerTest {
|
||||
|
||||
assertEquals(200, handler.handle("RestoreDBClusterFromSnapshot", p).getStatus());
|
||||
verify(service).restoreDbClusterFromSnapshot("restored", "snapshot", "aurora-postgresql",
|
||||
null, null, null, null, null, null, enabled, null, Map.of(), null);
|
||||
null, null, null, null, null, null, enabled, null, false, Map.of(), null);
|
||||
p.putSingle("SourceDBClusterIdentifier", "source");
|
||||
p.putSingle("UseLatestRestorableTime", "true");
|
||||
assertEquals(200, handler.handle("RestoreDBClusterToPointInTime", p).getStatus());
|
||||
verify(service).restoreDbClusterToPointInTime("restored", "source", null, null, null, true,
|
||||
null, null, null, enabled, null, Map.of(), null);
|
||||
null, null, null, enabled, null, false, Map.of(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -6490,7 +6490,7 @@ class RdsServiceTest {
|
||||
|
||||
AwsException clusterFault = assertThrows(AwsException.class, () -> rdsService.restoreDbClusterToPointInTime(
|
||||
"pitr-cluster-target", "pitr-cluster", null, null, null, true,
|
||||
null, null, null, null, null, Map.of(), "us-east-1"));
|
||||
null, null, null, null, null, false, Map.of(), "us-east-1"));
|
||||
assertEquals("InvalidDBClusterStateFault", clusterFault.getErrorCode());
|
||||
assertEquals("DBClusterNotFoundFault", assertThrows(AwsException.class,
|
||||
() -> rdsService.getDbCluster("pitr-cluster-target")).getErrorCode());
|
||||
@@ -8008,9 +8008,9 @@ class RdsServiceTest {
|
||||
|
||||
DbCluster restored = "snapshot".equals(path)
|
||||
? rdsService.restoreDbClusterFromSnapshot("iam-restored", "iam-snapshot", "aurora-postgresql",
|
||||
null, null, null, null, null, null, requested, null, null, "us-east-1")
|
||||
null, null, null, null, null, null, requested, null, false, null, "us-east-1")
|
||||
: rdsService.restoreDbClusterToPointInTime("iam-restored", "iam-source", null, null,
|
||||
null, true, null, null, null, requested, null, null, "us-east-1");
|
||||
null, true, null, null, null, requested, null, false, null, "us-east-1");
|
||||
|
||||
assertEquals(expected, restored.isIamDatabaseAuthenticationEnabled());
|
||||
assertEquals(expected, rdsService.getDbCluster("iam-restored").isIamDatabaseAuthenticationEnabled());
|
||||
@@ -8034,7 +8034,7 @@ class RdsServiceTest {
|
||||
|
||||
// SnapshotIdentifier takes the ARN as well as the name, as aws_rds_cluster commonly passes it.
|
||||
DbCluster restored = rdsService.restoreDbClusterFromSnapshot("restored-cluster", copy.getDbClusterSnapshotArn(),
|
||||
"aurora-postgresql", null, null, null, null, null, null, null, null, Map.of("env", "restore"), "us-east-1");
|
||||
"aurora-postgresql", null, null, null, null, null, null, null, null, false, Map.of("env", "restore"), "us-east-1");
|
||||
assertEquals("restored-cluster", restored.getDbClusterIdentifier());
|
||||
assertEquals("admin", restored.getMasterUsername());
|
||||
assertEquals("dbname", restored.getDatabaseName());
|
||||
@@ -8044,11 +8044,11 @@ class RdsServiceTest {
|
||||
|
||||
assertEquals("InvalidParameterValue", assertThrows(AwsException.class,
|
||||
() -> rdsService.restoreDbClusterFromSnapshot("mysql-cluster", "csnap", "aurora-mysql",
|
||||
null, null, null, null, null, null, null, null, null, "us-east-1")).getErrorCode());
|
||||
null, null, null, null, null, null, null, null, false, null, "us-east-1")).getErrorCode());
|
||||
assertEquals("DBClusterSnapshotNotFoundFault", assertThrows(AwsException.class,
|
||||
() -> rdsService.restoreDbClusterFromSnapshot("other-cluster",
|
||||
"arn:aws:rds:us-east-1:123456789012:cluster-snapshot:absent", "aurora-postgresql",
|
||||
null, null, null, null, null, null, null, null, null, "us-east-1")).getErrorCode());
|
||||
null, null, null, null, null, null, null, null, false, null, "us-east-1")).getErrorCode());
|
||||
|
||||
DbClusterSnapshot deleted = rdsService.deleteDbClusterSnapshot("csnap");
|
||||
assertEquals("deleted", deleted.getStatus());
|
||||
@@ -8062,13 +8062,29 @@ class RdsServiceTest {
|
||||
() -> rdsService.deleteDbClusterSnapshot("csnap-copy")).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedProtectedClusterRestoreLeavesNoCluster() {
|
||||
clusterSnapshotOfNewCluster("csnap");
|
||||
doThrow(new RuntimeException("failed restore"))
|
||||
.when(containerManager).restorePostgresSnapshot(any(), eq("admin"), eq("CLUSTER_DUMP"));
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class,
|
||||
() -> rdsService.restoreDbClusterFromSnapshot("restored-cluster", "csnap", "aurora-postgresql",
|
||||
null, null, null, null, null, null, null, null, true, null, "us-east-1"));
|
||||
|
||||
assertEquals("InvalidDBClusterSnapshotStateFault", failure.getErrorCode());
|
||||
assertEquals(0, failure.getCause().getSuppressed().length);
|
||||
assertEquals("DBClusterNotFoundFault", assertThrows(AwsException.class,
|
||||
() -> rdsService.getDbCluster("restored-cluster")).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void restoreClusterFromSnapshotUsesRequestedPortAndReleasesItOnDelete() {
|
||||
clusterSnapshotOfNewCluster("csnap");
|
||||
|
||||
DbCluster restored = rdsService.restoreDbClusterFromSnapshot("restored-cluster", "csnap",
|
||||
"aurora-postgresql", null, 7005, null, null, null, null, null, null,
|
||||
null, "us-east-1");
|
||||
false, null, "us-east-1");
|
||||
assertEquals(7005, restored.getEndpoint().port());
|
||||
assertEquals(7005, restored.getProxyPort());
|
||||
assertEquals(7005, rdsService.getDbCluster("restored-cluster").getEndpoint().port());
|
||||
@@ -8078,23 +8094,23 @@ class RdsServiceTest {
|
||||
assertEquals("InvalidParameterValue", assertThrows(AwsException.class,
|
||||
() -> rdsService.restoreDbClusterFromSnapshot("duplicate-port", "csnap",
|
||||
"aurora-postgresql", null, 7005, null, null, null, null, null, null,
|
||||
null, "us-east-1")).getErrorCode());
|
||||
false, null, "us-east-1")).getErrorCode());
|
||||
|
||||
DbCluster outsideRange = rdsService.restoreDbClusterFromSnapshot("outside-range", "csnap",
|
||||
"aurora-postgresql", null, 5432, null, null, null, null, null, null,
|
||||
null, "us-east-1");
|
||||
false, null, "us-east-1");
|
||||
assertNotEquals(5432, outsideRange.getProxyPort());
|
||||
assertTrue(outsideRange.getProxyPort() >= 7000 && outsideRange.getProxyPort() <= 7099);
|
||||
assertNotEquals(restored.getProxyPort(), outsideRange.getProxyPort());
|
||||
assertEquals("InvalidParameterValue", assertThrows(AwsException.class,
|
||||
() -> rdsService.restoreDbClusterFromSnapshot("invalid-port", "csnap",
|
||||
"aurora-postgresql", null, 1149, null, null, null, null, null, null,
|
||||
null, "us-east-1")).getErrorCode());
|
||||
false, null, "us-east-1")).getErrorCode());
|
||||
|
||||
rdsService.deleteDbCluster("restored-cluster");
|
||||
DbCluster reused = rdsService.restoreDbClusterFromSnapshot("reused-port", "csnap",
|
||||
"aurora-postgresql", null, 7005, null, null, null, null, null, null,
|
||||
null, "us-east-1");
|
||||
false, null, "us-east-1");
|
||||
assertEquals(7005, reused.getEndpoint().port());
|
||||
}
|
||||
|
||||
|
||||
@@ -447,7 +447,6 @@ AWS::RDS::DBCluster DBClusterInstanceClass accepted and ignored
|
||||
AWS::RDS::DBCluster DBInstanceParameterGroupName accepted and ignored
|
||||
AWS::RDS::DBCluster DatabaseInsightsMode accepted and ignored
|
||||
AWS::RDS::DBCluster DeleteAutomatedBackups accepted and ignored
|
||||
AWS::RDS::DBCluster DeletionProtection accepted and ignored
|
||||
AWS::RDS::DBCluster Domain accepted and ignored
|
||||
AWS::RDS::DBCluster DomainIAMRoleName accepted and ignored
|
||||
AWS::RDS::DBCluster EnableCloudwatchLogsExports accepted and ignored
|
||||
|
||||
|
Reference in new issue
Block a user