mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(rds): store and describe DB cluster monitoring and Insights settings (#9095)
CreateDBCluster and ModifyDBCluster dropped MonitoringInterval, MonitoringRoleArn, EnablePerformanceInsights, PerformanceInsightsRetentionPeriod and DatabaseInsightsMode, and DescribeDBClusters left them out, so the Terraform AWS provider planned the same change on every run for a cluster that sets them. DbCluster now keeps them, with the checks a DB instance gets plus advanced Database Insights needing Performance Insights with at least 465 days of retention. CreateDBCluster and ModifyDBCluster also check VpcSecurityGroupIds against EC2 as CreateDBInstance does. A modify runs these checks before any of its changes is stored, and a refused create leaves no cluster. An Aurora member reports its cluster's groups, and a cluster automated backup reports its cluster's backup window.
This commit is contained in:
1 parent
d096a6d64e
commit
ce02956615
9 files changed
+465
-30
No files matched your search
+7
-2
@@ -12,6 +12,8 @@ import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.floci.aws.testing.Ec2Requests.createDefaultVpcSecurityGroup;
|
||||
import static io.floci.aws.testing.Ec2Requests.ec2;
|
||||
import static io.floci.aws.testing.RdsRequests.auroraClusterWithMember;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
@@ -304,6 +306,8 @@ class CloudFormationRdsAssociatedRolesIntegrationTest {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "cfn-rds-sg-out-" + suffix;
|
||||
String clusterId = "cfn-sg-out-" + suffix;
|
||||
// ModifyDBCluster refuses a group EC2 does not know; the cluster is in the default VPC
|
||||
String outside = createDefaultVpcSecurityGroup("test", "us-east-1", "cfn-sg-outside-" + suffix);
|
||||
String cluster = """
|
||||
{"Resources": {"Cluster": {"Type": "AWS::RDS::DBCluster", "Properties": {
|
||||
"DBClusterIdentifier": "%s", "Engine": "aurora-postgresql",
|
||||
@@ -315,12 +319,12 @@ class CloudFormationRdsAssociatedRolesIntegrationTest {
|
||||
+ " \"PreferredMaintenanceWindow\": \"mon:05:00-mon:06:00\""));
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", clusterId)
|
||||
.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.1", "sg-outside")
|
||||
.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.1", outside)
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
stack("UpdateStack", stackName, cluster.formatted(clusterId, "password456", ""));
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
assertEquals(List.of("sg-outside"), clusterGroups(clusterId));
|
||||
assertEquals(List.of(outside), clusterGroups(clusterId));
|
||||
XmlPath xml = rds("DescribeDBClusters").formParam("DBClusterIdentifier", clusterId)
|
||||
.when().post("/").then().statusCode(200).extract().xmlPath();
|
||||
assertEquals("true", xml.getString("**.find { it.name() == 'DeletionProtection' }"));
|
||||
@@ -332,6 +336,7 @@ class CloudFormationRdsAssociatedRolesIntegrationTest {
|
||||
.formParam("DeletionProtection", "false").when().post("/");
|
||||
stack("DeleteStack", stackName, null);
|
||||
CfnStackWaits.awaitStackDeleted(stackName);
|
||||
ec2("DeleteSecurityGroup", "test", "us-east-1").formParam("GroupId", outside).when().post("/");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
package io.floci.aws.services.rds;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.floci.aws.testing.RdsMockProfile;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.ec2.Ec2Client;
|
||||
import software.amazon.awssdk.services.rds.RdsClient;
|
||||
import software.amazon.awssdk.services.rds.model.DBCluster;
|
||||
import software.amazon.awssdk.services.rds.model.DbClusterNotFoundException;
|
||||
import software.amazon.awssdk.services.rds.model.DbInstanceNotFoundException;
|
||||
import software.amazon.awssdk.services.rds.model.VpcSecurityGroupMembership;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.floci.aws.testing.AwsSdkErrors.assertAwsError;
|
||||
import static io.floci.aws.testing.RdsRequests.rdsClient;
|
||||
import static io.floci.aws.testing.RdsRequests.vpcSecurityGroupIds;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* The Enhanced Monitoring, Performance Insights and Database Insights settings of a DB cluster
|
||||
* round-trip from CreateDBCluster and ModifyDBCluster to DescribeDBClusters; the cluster's VPC
|
||||
* security groups must exist in its VPC; an Aurora member reports its cluster's groups; and a
|
||||
* retained automated backup reports its cluster's backup window. Before, the monitoring members were
|
||||
* dropped, so the Terraform AWS provider planned the same change on every run.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(RdsMockProfile.class)
|
||||
class RdsClusterSettingsIntegrationTest {
|
||||
|
||||
private static final String ACCOUNT = "135792468024";
|
||||
private static final String CLUSTER = "settings-cluster";
|
||||
private static final String DEFAULTS = "settings-defaults";
|
||||
private static final String REFUSED = "settings-refused";
|
||||
private static final String MEMBER = "settings-member";
|
||||
private static final String ROLE = "arn:aws:iam::" + ACCOUNT + ":role/rds-monitoring";
|
||||
|
||||
/** Frees the proxy ports the clusters hold, which later tests in the same run count on. */
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
try (RdsClient rds = rdsClient("us-east-1", ACCOUNT)) {
|
||||
try {
|
||||
rds.deleteDBInstance(request -> request.dbInstanceIdentifier(MEMBER).skipFinalSnapshot(true));
|
||||
} catch (DbInstanceNotFoundException ignored) {
|
||||
// the test failed before it created the member, or already deleted it
|
||||
}
|
||||
for (String id : List.of(CLUSTER, DEFAULTS, REFUSED)) {
|
||||
try {
|
||||
rds.deleteDBCluster(request -> request.dbClusterIdentifier(id).skipFinalSnapshot(true));
|
||||
} catch (DbClusterNotFoundException ignored) {
|
||||
// never created, refused, or already deleted by the test
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterSettingsRoundTripThroughCreateAndModify() {
|
||||
try (Ec2Client ec2 = AwsTestClients.create(Ec2Client.builder(), ACCOUNT, Region.US_EAST_1);
|
||||
RdsClient rds = rdsClient("us-east-1", ACCOUNT)) {
|
||||
String vpcId = ec2.createVpc(request -> request.cidrBlock("10.51.0.0/16")).vpc().vpcId();
|
||||
String app = group(ec2, vpcId, "app");
|
||||
String other = group(ec2, vpcId, "other");
|
||||
String elsewhereVpc = ec2.createVpc(request -> request.cidrBlock("10.52.0.0/16")).vpc().vpcId();
|
||||
String elsewhere = group(ec2, elsewhereVpc, "elsewhere");
|
||||
subnetGroup(ec2, rds, "settings-subnets", vpcId, "10.51");
|
||||
|
||||
// A cluster that names none of them takes the AWS defaults.
|
||||
rds.createDBCluster(request -> request.dbClusterIdentifier(DEFAULTS).engine("aurora-postgresql")
|
||||
.masterUsername("dbadmin").masterUserPassword("password123")
|
||||
.dbSubnetGroupName("settings-subnets"));
|
||||
DBCluster defaults = describe(rds, DEFAULTS);
|
||||
assertEquals(0, defaults.monitoringInterval());
|
||||
assertNull(defaults.monitoringRoleArn());
|
||||
assertFalse(defaults.performanceInsightsEnabled());
|
||||
assertNull(defaults.performanceInsightsRetentionPeriod());
|
||||
assertEquals("standard", defaults.databaseInsightsModeAsString());
|
||||
|
||||
rds.createDBCluster(request -> request.dbClusterIdentifier(CLUSTER).engine("aurora-postgresql")
|
||||
.masterUsername("dbadmin").masterUserPassword("password123")
|
||||
.dbSubnetGroupName("settings-subnets").vpcSecurityGroupIds(app)
|
||||
.preferredBackupWindow("03:00-06:00").preferredMaintenanceWindow("Sun:23:00-Mon:02:00")
|
||||
.monitoringInterval(60).monitoringRoleArn(ROLE)
|
||||
.enablePerformanceInsights(true).performanceInsightsRetentionPeriod(558)
|
||||
.databaseInsightsMode("advanced"));
|
||||
DBCluster created = describe(rds, CLUSTER);
|
||||
assertEquals(60, created.monitoringInterval());
|
||||
assertEquals(ROLE, created.monitoringRoleArn());
|
||||
assertTrue(created.performanceInsightsEnabled());
|
||||
assertEquals(558, created.performanceInsightsRetentionPeriod());
|
||||
assertEquals("advanced", created.databaseInsightsModeAsString());
|
||||
|
||||
// A modify changes what it names and keeps the rest.
|
||||
rds.modifyDBCluster(request -> request.dbClusterIdentifier(CLUSTER).applyImmediately(true)
|
||||
.vpcSecurityGroupIds(other).preferredBackupWindow("06:30-07:30"));
|
||||
DBCluster modified = describe(rds, CLUSTER);
|
||||
assertEquals(List.of(other), groups(modified));
|
||||
assertEquals(60, modified.monitoringInterval());
|
||||
assertEquals(558, modified.performanceInsightsRetentionPeriod());
|
||||
assertEquals("advanced", modified.databaseInsightsModeAsString());
|
||||
|
||||
rds.modifyDBCluster(request -> request.dbClusterIdentifier(CLUSTER).applyImmediately(true)
|
||||
.databaseInsightsMode("standard").enablePerformanceInsights(false).monitoringInterval(0));
|
||||
DBCluster disabled = describe(rds, CLUSTER);
|
||||
assertEquals("standard", disabled.databaseInsightsModeAsString());
|
||||
assertFalse(disabled.performanceInsightsEnabled());
|
||||
assertNull(disabled.performanceInsightsRetentionPeriod());
|
||||
assertEquals(0, disabled.monitoringInterval());
|
||||
|
||||
// Refused requests change nothing: a group of another VPC, one EC2 does not know, a bad
|
||||
// interval, advanced Database Insights without Performance Insights.
|
||||
assertAwsError("InvalidParameterCombination", 400, () -> rds.modifyDBCluster(request -> request
|
||||
.dbClusterIdentifier(CLUSTER).vpcSecurityGroupIds(elsewhere)));
|
||||
assertAwsError("InvalidParameterValue", 400, () -> rds.modifyDBCluster(request -> request
|
||||
.dbClusterIdentifier(CLUSTER).vpcSecurityGroupIds("sg-0123456789abcdef0")));
|
||||
assertAwsError("InvalidParameterValue", 400, () -> rds.modifyDBCluster(request -> request
|
||||
.dbClusterIdentifier(CLUSTER).monitoringInterval(7)));
|
||||
assertAwsError("InvalidParameterCombination", 400, () -> rds.modifyDBCluster(request -> request
|
||||
.dbClusterIdentifier(CLUSTER).databaseInsightsMode("advanced")));
|
||||
assertEquals(List.of(other), groups(describe(rds, CLUSTER)));
|
||||
assertEquals("standard", describe(rds, CLUSTER).databaseInsightsModeAsString());
|
||||
|
||||
// A refused setting refuses the whole modify, so the other changes it names are not stored.
|
||||
assertAwsError("InvalidParameterCombination", 400, () -> rds.modifyDBCluster(request -> request
|
||||
.dbClusterIdentifier(CLUSTER).backupRetentionPeriod(14).deletionProtection(true)
|
||||
.vpcSecurityGroupIds(elsewhere)));
|
||||
assertAwsError("InvalidParameterCombination", 400, () -> rds.modifyDBCluster(request -> request
|
||||
.dbClusterIdentifier(CLUSTER).backupRetentionPeriod(14).monitoringInterval(30)
|
||||
.databaseInsightsMode("advanced")));
|
||||
DBCluster unchanged = describe(rds, CLUSTER);
|
||||
assertEquals(1, unchanged.backupRetentionPeriod());
|
||||
assertFalse(unchanged.deletionProtection());
|
||||
assertEquals(0, unchanged.monitoringInterval());
|
||||
|
||||
assertAwsError("InvalidParameterCombination", 400, () -> rds.createDBCluster(request -> request
|
||||
.dbClusterIdentifier(REFUSED).engine("aurora-postgresql")
|
||||
.masterUsername("dbadmin").masterUserPassword("password123")
|
||||
.dbSubnetGroupName("settings-subnets").vpcSecurityGroupIds(elsewhere)));
|
||||
assertAwsError("InvalidParameterCombination", 400, () -> rds.createDBCluster(request -> request
|
||||
.dbClusterIdentifier(REFUSED).engine("aurora-postgresql")
|
||||
.masterUsername("dbadmin").masterUserPassword("password123")
|
||||
.monitoringInterval(60)));
|
||||
assertThrows(DbClusterNotFoundException.class, () -> describe(rds, REFUSED));
|
||||
|
||||
// An Aurora member keeps no groups of its own and reports its cluster's.
|
||||
rds.createDBInstance(request -> request.dbInstanceIdentifier(MEMBER).dbClusterIdentifier(CLUSTER)
|
||||
.engine("aurora-postgresql").dbInstanceClass("db.r5.large"));
|
||||
assertEquals(List.of(other), vpcSecurityGroupIds(rds, MEMBER));
|
||||
rds.modifyDBCluster(request -> request.dbClusterIdentifier(CLUSTER).vpcSecurityGroupIds(app));
|
||||
assertEquals(List.of(app), vpcSecurityGroupIds(rds, MEMBER));
|
||||
|
||||
// A retained automated backup reports the window of the cluster it was taken from.
|
||||
rds.deleteDBInstance(request -> request.dbInstanceIdentifier(MEMBER).skipFinalSnapshot(true));
|
||||
rds.deleteDBCluster(request -> request.dbClusterIdentifier(CLUSTER).skipFinalSnapshot(true)
|
||||
.deleteAutomatedBackups(false));
|
||||
assertEquals("06:30-07:30", rds.describeDBClusterAutomatedBackups(request -> request
|
||||
.dbClusterIdentifier(CLUSTER)).dbClusterAutomatedBackups().getFirst().preferredBackupWindow());
|
||||
}
|
||||
}
|
||||
|
||||
private static DBCluster describe(RdsClient rds, String id) {
|
||||
return rds.describeDBClusters(request -> request.dbClusterIdentifier(id)).dbClusters().getFirst();
|
||||
}
|
||||
|
||||
private static List<String> groups(DBCluster cluster) {
|
||||
return cluster.vpcSecurityGroups().stream().map(VpcSecurityGroupMembership::vpcSecurityGroupId).toList();
|
||||
}
|
||||
|
||||
private static void subnetGroup(Ec2Client ec2, RdsClient rds, String name, String vpcId, String prefix) {
|
||||
List<String> subnetIds = List.of(subnet(ec2, vpcId, prefix + ".1.0/24", "us-east-1a"),
|
||||
subnet(ec2, vpcId, prefix + ".2.0/24", "us-east-1b"));
|
||||
rds.createDBSubnetGroup(request -> request.dbSubnetGroupName(name).dbSubnetGroupDescription(name)
|
||||
.subnetIds(subnetIds));
|
||||
}
|
||||
|
||||
private static String subnet(Ec2Client ec2, String vpcId, String cidr, String zone) {
|
||||
return ec2.createSubnet(request -> request.vpcId(vpcId).cidrBlock(cidr).availabilityZone(zone))
|
||||
.subnet().subnetId();
|
||||
}
|
||||
|
||||
private static String group(Ec2Client ec2, String vpcId, String name) {
|
||||
return ec2.createSecurityGroup(request -> request.vpcId(vpcId).groupName(name).description(name)).groupId();
|
||||
}
|
||||
}
|
||||
+34
-12
@@ -18,6 +18,8 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static io.floci.aws.testing.Ec2Requests.createDefaultVpcSecurityGroup;
|
||||
import static io.floci.aws.testing.Ec2Requests.ec2;
|
||||
import static io.floci.aws.testing.RdsRequests.createAuroraPostgresCluster;
|
||||
import static io.floci.aws.testing.RdsRequests.rds;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
@@ -57,10 +59,25 @@ class RdsClusterVpcSecurityGroupsIntegrationTest {
|
||||
.when().post("/").then().statusCode(200).extract().asString());
|
||||
}
|
||||
|
||||
private final List<String> createdGroups = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* A new security group of the default VPC, which a cluster created without a DB subnet group is
|
||||
* placed in: CreateDBCluster and ModifyDBCluster refuse a group EC2 does not know.
|
||||
*/
|
||||
private String securityGroup(String name) {
|
||||
String groupId = createDefaultVpcSecurityGroup("test", "us-east-1", name + "-" + System.nanoTime());
|
||||
createdGroups.add(groupId);
|
||||
return groupId;
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("SkipFinalSnapshot", "true").when().post("/");
|
||||
for (String groupId : createdGroups) {
|
||||
ec2("DeleteSecurityGroup", "test", "us-east-1").formParam("GroupId", groupId).when().post("/");
|
||||
}
|
||||
// after the cluster, which may reference it; absent in most tests
|
||||
rds("DeleteDBClusterParameterGroup").formParam("DBClusterParameterGroupName", "pg-rejected")
|
||||
.when().post("/");
|
||||
@@ -68,25 +85,28 @@ class RdsClusterVpcSecurityGroupsIntegrationTest {
|
||||
|
||||
@Test
|
||||
void createStoresRequestedGroupsAndModifyReplacesThem() {
|
||||
String first = securityGroup("first");
|
||||
String second = securityGroup("second");
|
||||
String third = securityGroup("third");
|
||||
String created = createAuroraPostgresCluster(ID)
|
||||
.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.1", "sg-abcdef01")
|
||||
.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.1", first)
|
||||
.when().post("/").then().statusCode(200).extract().asString();
|
||||
assertEquals(List.of("sg-abcdef01"), groupIds(created));
|
||||
assertEquals(List.of("sg-abcdef01"), describedGroupIds());
|
||||
assertEquals(List.of(first), groupIds(created));
|
||||
assertEquals(List.of(first), describedGroupIds());
|
||||
|
||||
rds("ModifyDBCluster")
|
||||
.formParam("DBClusterIdentifier", ID)
|
||||
.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.1", "sg-11111111")
|
||||
.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.2", "sg-22222222")
|
||||
.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.1", second)
|
||||
.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.2", third)
|
||||
.when().post("/").then().statusCode(200);
|
||||
assertEquals(List.of("sg-11111111", "sg-22222222"), describedGroupIds());
|
||||
assertEquals(List.of(second, third), describedGroupIds());
|
||||
|
||||
// A modify that does not name VpcSecurityGroupIds leaves them alone.
|
||||
rds("ModifyDBCluster")
|
||||
.formParam("DBClusterIdentifier", ID)
|
||||
.formParam("EnableIAMDatabaseAuthentication", "true")
|
||||
.when().post("/").then().statusCode(200);
|
||||
assertEquals(List.of("sg-11111111", "sg-22222222"), describedGroupIds());
|
||||
assertEquals(List.of(second, third), describedGroupIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -271,21 +291,22 @@ class RdsClusterVpcSecurityGroupsIntegrationTest {
|
||||
rds("CreateDBClusterParameterGroup").formParam("DBClusterParameterGroupName", "pg-rejected")
|
||||
.formParam("DBParameterGroupFamily", "aurora-postgresql15").formParam("Description", "d")
|
||||
.when().post("/").then().statusCode(200);
|
||||
String old = securityGroup("old");
|
||||
createAuroraPostgresCluster(ID).formParam("MasterUserPassword", "original-password1")
|
||||
.formParam("VpcSecurityGroupIds.member.1", "sg-old").when().post("/").then().statusCode(200);
|
||||
.formParam("VpcSecurityGroupIds.member.1", old).when().post("/").then().statusCode(200);
|
||||
String groupBefore = described("DBClusterParameterGroup");
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("DeletionProtection", "garbage").formParam("BackupRetentionPeriod", "9")
|
||||
.formParam("EnableIAMDatabaseAuthentication", "true")
|
||||
.formParam("MasterUserPassword", "changed-password2")
|
||||
.formParam("VpcSecurityGroupIds.member.1", "sg-new")
|
||||
.formParam("VpcSecurityGroupIds.member.1", securityGroup("new"))
|
||||
.formParam("DBClusterParameterGroupName", "pg-rejected")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
assertEquals("1", described("BackupRetentionPeriod"));
|
||||
assertEquals("false", described("IAMDatabaseAuthenticationEnabled"));
|
||||
assertEquals("false", described("DeletionProtection"));
|
||||
assertEquals(List.of("sg-old"), describedGroupIds());
|
||||
assertEquals(List.of(old), describedGroupIds());
|
||||
assertEquals(groupBefore, described("DBClusterParameterGroup"));
|
||||
}
|
||||
|
||||
@@ -298,12 +319,13 @@ class RdsClusterVpcSecurityGroupsIntegrationTest {
|
||||
|
||||
@Test
|
||||
void modifyWithEmptySecurityGroupMemberChangesNothing() {
|
||||
createAuroraPostgresCluster(ID).formParam("VpcSecurityGroupIds.member.1", "sg-old").when().post("/").then().statusCode(200);
|
||||
String old = securityGroup("old");
|
||||
createAuroraPostgresCluster(ID).formParam("VpcSecurityGroupIds.member.1", old).when().post("/").then().statusCode(200);
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("VpcSecurityGroupIds.member.1", "").formParam("BackupRetentionPeriod", "9")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
assertEquals("1", described("BackupRetentionPeriod"));
|
||||
assertEquals(List.of("sg-old"), describedGroupIds());
|
||||
assertEquals(List.of(old), describedGroupIds());
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,18 @@ public final class Ec2Requests {
|
||||
.securityGroups().getFirst().groupId();
|
||||
}
|
||||
|
||||
/** Creates security group {@code name} in the default VPC of {@code accountId} in {@code region}; returns its id. */
|
||||
public static String createDefaultVpcSecurityGroup(String accountId, String region, String name) {
|
||||
String vpcId = ec2("DescribeVpcs", accountId, region)
|
||||
.formParam("Filter.1.Name", "isDefault").formParam("Filter.1.Value.1", "true")
|
||||
.when().post("/").then().statusCode(200).extract().xmlPath()
|
||||
.getString("DescribeVpcsResponse.vpcSet.item[0].vpcId");
|
||||
return ec2("CreateSecurityGroup", accountId, region)
|
||||
.formParam("GroupName", name).formParam("GroupDescription", name).formParam("VpcId", vpcId)
|
||||
.when().post("/").then().statusCode(200).extract().xmlPath()
|
||||
.getString("CreateSecurityGroupResponse.groupId");
|
||||
}
|
||||
|
||||
public static RequestSpecification ec2(String action, String accountId, String region) {
|
||||
return given().header("Authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=" + accountId + "/20261016/" + region + "/ec2/aws4_request")
|
||||
|
||||
Reference in new issue
Block a user