fix(ec2): ensure default VPC network resource IDs are unique per account in same region (#9055)

This commit is contained in:
noy-solvin authored and GitHub committed 2026-11-24 07:03:14 -04:00
1 parent 924040aaa1
commit 7d317fbfa6
63 files changed
+409 -344

No files matched your search

@@ -339,7 +339,7 @@ public class DocDbService {
}
RdsSecurityGroups.requireInVpc(ec2Service, region, securityGroups, null);
} else if (create) {
securityGroups = List.of(resolveDefaultSecurityGroupId(ec2Service, region));
securityGroups = List.of(resolveDefaultSecurityGroupId(ec2Service, region, regionResolver.getAccountId()));
}
String kmsKeyArn = resolveKmsKeyArn(settings.kmsKeyId(), region);
String[] windows = BackupWindows.effectiveWindows(create, settings.preferredBackupWindow(),
@@ -352,13 +352,10 @@ public class DocDbService {
}
/** The security group a cluster's VPC security group ids fall back to: the service's
* resolved default when it is up, the region's computed default otherwise. */
private static String resolveDefaultSecurityGroupId(Ec2Service ec2Service, String region) {
if (ec2Service == null) {
return Ec2Service.defaultSecurityGroupId(region);
}
String resolved = ec2Service.resolveDefaultSecurityGroupId(region);
return resolved != null ? resolved : Ec2Service.defaultSecurityGroupId(region);
* resolved default when it is up, the account and region's computed default otherwise (#7307). */
private static String resolveDefaultSecurityGroupId(Ec2Service ec2Service, String region, String accountId) {
String resolved = ec2Service != null ? ec2Service.resolveDefaultSecurityGroupId(region) : null;
return resolved != null ? resolved : Ec2Service.defaultSecurityGroupId(region, accountId);
}
/** The family of the group a cluster is on; a group deleted since is judged by nothing. */
@@ -471,7 +468,8 @@ public class DocDbService {
changed = true;
}
if (cluster.getVpcSecurityGroupIds() == null || cluster.getVpcSecurityGroupIds().isEmpty()) {
cluster.setVpcSecurityGroupIds(List.of(resolveDefaultSecurityGroupId(ec2Service, region)));
cluster.setVpcSecurityGroupIds(List.of(
resolveDefaultSecurityGroupId(ec2Service, region, regionResolver.getAccountId())));
changed = true;
}
if (cluster.getPreferredBackupWindow() == null) {
@@ -1834,8 +1834,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
ensureDefaultDhcpOptions(region, ownerAccountId);
LOG.debugv("Seeding default EC2 resources for region {0}", region);
// Default VPC
String vpcId = defaultVpcId(region);
// Default VPC (#7307: derive default resource ids from both ownerAccountId and region)
String vpcId = defaultVpcId(region, ownerAccountId);
Vpc defaultVpc = new Vpc();
defaultVpc.setVpcId(vpcId);
defaultVpc.setCidrBlock("172.31.0.0/16");
@@ -1844,7 +1844,10 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
defaultVpc.setOwnerId(ownerAccountId);
defaultVpc.setRegion(region);
defaultVpc.getCidrBlockAssociationSet().add(
new VpcCidrBlockAssociation("vpc-cidr-assoc-" + Ec2Ids.stableHex("vpc-cidr-assoc::" + region), "172.31.0.0/16"));
new VpcCidrBlockAssociation(
"vpc-cidr-assoc-" + Ec2Ids.stableHex(
"vpc-cidr-assoc::" + accountIdOrDefault(ownerAccountId) + "::" + region),
"172.31.0.0/16"));
vpcs.put(key(region, vpcId), defaultVpc);
declareVpcNetwork(region, vpcId, "172.31.0.0/16");
@@ -1852,9 +1855,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
String[] azSuffixes = MODELLED_ZONE_SUFFIXES;
String[] cidrBlocks = {"172.31.0.0/20", "172.31.16.0/20", "172.31.32.0/20"};
String[] subnetIds = {
defaultSubnetId(region, azSuffixes[0]),
defaultSubnetId(region, azSuffixes[1]),
defaultSubnetId(region, azSuffixes[2])};
defaultSubnetId(region, azSuffixes[0], ownerAccountId),
defaultSubnetId(region, azSuffixes[1], ownerAccountId),
defaultSubnetId(region, azSuffixes[2], ownerAccountId)};
for (int i = 0; i < 3; i++) {
Subnet subnet = new Subnet();
subnet.setSubnetId(subnetIds[i]);
@@ -1873,10 +1876,10 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
declareSubnetNetwork(region, vpcId, subnetIds[i], cidrBlocks[i]);
}
createDefaultSecurityGroup(region, vpcId, defaultSecurityGroupId(region));
createDefaultSecurityGroup(region, vpcId, defaultSecurityGroupId(region, ownerAccountId));
// Default internet gateway
String igwId = defaultInternetGatewayId(region);
String igwId = defaultInternetGatewayId(region, ownerAccountId);
InternetGateway igw = new InternetGateway();
igw.setInternetGatewayId(igwId);
igw.setOwnerId(ownerAccountId);
@@ -1884,8 +1887,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
igw.getAttachments().add(new InternetGatewayAttachment(vpcId, "available"));
internetGateways.put(key(region, igwId), igw);
String rtId = defaultRouteTableId(region);
String rtAssocId = defaultRouteTableAssociationId(region);
String rtId = defaultRouteTableId(region, ownerAccountId);
String rtAssocId = defaultRouteTableAssociationId(region, ownerAccountId);
createMainRouteTable(region, defaultVpc, rtId, rtAssocId);
RouteTable mainRt = routeTables.get(key(region, rtId)).orElse(null);
@@ -1894,12 +1897,12 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
}
// Default NACL - create and associate with default subnets
String defaultAclId = defaultNetworkAclId(region);
String defaultAclId = defaultNetworkAclId(region, ownerAccountId);
createDefaultNetworkAcl(region, vpcId, defaultAclId);
NetworkAcl defaultAcl = networkAcls.get(key(region, defaultAclId)).orElse(null);
if (defaultAcl != null) {
for (String subnetId : subnetIds) {
String assocId = defaultNetworkAclAssociationId(region, subnetId);
String assocId = defaultNetworkAclAssociationId(region, subnetId, ownerAccountId);
NetworkAclAssociation assoc = new NetworkAclAssociation();
assoc.setNetworkAclAssociationId(assocId);
assoc.setNetworkAclId(defaultAclId);
@@ -2527,75 +2530,83 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
return region + "::" + id;
}
// Default resource ids must be derived per region (lex00/floci#21): every region seeds its own
// default VPC/subnets/security group independently, but a literal id like "vpc-default"
// is identical text in every region's response even though storage itself is already
// correctly keyed by region. RdsService derives the same ids from these methods so its
// default DB subnet group resolves against the right region's default VPC.
public static String defaultVpcId(String region) {
return "vpc-" + Ec2Ids.stableHex("vpc::" + region);
private static final String DEFAULT_ACCOUNT_ID = "000000000000";
// Default resource ids must be derived per account and region (lex00/floci#21, #7307): every
// account in every region seeds its own default VPC/subnets/security group independently, so
// their ids must include both the owning account and the region. RdsService and DocDbService
// derive the same ids from these methods so default subnet groups and security groups resolve
// against the caller's default VPC.
public static String defaultVpcId(String region, String ownerAccountId) {
return "vpc-" + Ec2Ids.stableHex("vpc::" + accountIdOrDefault(ownerAccountId) + "::" + region);
}
public static String defaultSubnetId(String region, String azSuffix) {
return "subnet-" + Ec2Ids.stableHex("subnet::" + region + "::" + azSuffix);
public static String defaultSubnetId(String region, String azSuffix, String ownerAccountId) {
return "subnet-" + Ec2Ids.stableHex(
"subnet::" + accountIdOrDefault(ownerAccountId) + "::" + region + "::" + azSuffix);
}
public static boolean isModelledAvailabilityZone(String region, String zone) {
return Arrays.stream(MODELLED_ZONE_SUFFIXES).anyMatch(suffix -> (region + suffix).equals(zone));
}
public static String defaultSecurityGroupId(String region) {
return "sg-" + Ec2Ids.stableHex("sg::" + region);
public static String defaultSecurityGroupId(String region, String ownerAccountId) {
return "sg-" + Ec2Ids.stableHex("sg::" + accountIdOrDefault(ownerAccountId) + "::" + region);
}
/**
* Internet Gateway ID for the default network in a region: igw-<17 hex digits>.
*/
public static String defaultInternetGatewayId(String region) {
return "igw-" + Ec2Ids.stableHex("igw::" + region);
public static String defaultInternetGatewayId(String region, String ownerAccountId) {
return "igw-" + Ec2Ids.stableHex("igw::" + accountIdOrDefault(ownerAccountId) + "::" + region);
}
/**
* Main Route Table ID for the default network in a region: rtb-<17 hex digits>.
*/
public static String defaultRouteTableId(String region) {
return "rtb-" + Ec2Ids.stableHex("rtb::" + region);
public static String defaultRouteTableId(String region, String ownerAccountId) {
return "rtb-" + Ec2Ids.stableHex("rtb::" + accountIdOrDefault(ownerAccountId) + "::" + region);
}
/**
* Main Route Table Association ID for the default network in a region: rtbassoc-<17 hex digits>.
*/
public static String defaultRouteTableAssociationId(String region) {
return "rtbassoc-" + Ec2Ids.stableHex("rtbassoc::" + region);
public static String defaultRouteTableAssociationId(String region, String ownerAccountId) {
return "rtbassoc-" + Ec2Ids.stableHex("rtbassoc::" + accountIdOrDefault(ownerAccountId) + "::" + region);
}
/**
* Default Network ACL ID for the default network in a region: acl-<17 hex digits>.
*/
public static String defaultNetworkAclId(String region) {
return "acl-" + Ec2Ids.stableHex("acl::" + region);
public static String defaultNetworkAclId(String region, String ownerAccountId) {
return "acl-" + Ec2Ids.stableHex("acl::" + accountIdOrDefault(ownerAccountId) + "::" + region);
}
/**
* Network ACL Association ID for a default subnet in a region: aclassoc-<17 hex digits>.
*/
public static String defaultNetworkAclAssociationId(String region, String subnetId) {
return "aclassoc-" + Ec2Ids.stableHex("aclassoc::" + region + "::" + subnetId);
public static String defaultNetworkAclAssociationId(String region, String subnetId, String ownerAccountId) {
return "aclassoc-" + Ec2Ids.stableHex(
"aclassoc::" + accountIdOrDefault(ownerAccountId) + "::" + region + "::" + subnetId);
}
private static String accountIdOrDefault(String ownerAccountId) {
return ownerAccountId == null || ownerAccountId.isBlank() ? DEFAULT_ACCOUNT_ID : ownerAccountId.trim();
}
// Resolves the default VPC/security-group id actually on file for a region, falling back to
// the pre-lex00/floci#21 unscoped literal ("vpc-default"/"sg-default") when storage was persisted before
// ids were made region-scoped. Seeding (ensureDefaultResources) always assigns the new
// region-scoped id going forward; these resolvers only cover lookups against what may already
// be on disk. Without this, a region seeded under the old scheme would silently lose its
// default VPC/security group to every caller that resolves them by computed id.
// account- and region-scoped id going forward; these resolvers only cover lookups against what
// may already be on disk. Without this, a region seeded under the old scheme would silently
// lose its default VPC/security group to every caller that resolves them by computed id.
public String resolveDefaultVpcId(String region) {
String scoped = defaultVpcId(region);
String scoped = defaultVpcId(region, callerAccountId());
if (vpcs.get(key(region, scoped)).isPresent()) {
return scoped;
}
// Legacy literals from before ids became region-scoped.
for (String legacy : List.of("vpc-default", "vpc-default-" + region)) {
// Legacy literals from before ids became account- and region-scoped.
for (String legacy : List.of("vpc-" + Ec2Ids.stableHex("vpc::" + region), "vpc-default", "vpc-default-" + region)) {
if (vpcs.get(key(region, legacy)).isPresent()) {
return legacy;
}
@@ -2604,12 +2615,12 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
}
public String resolveDefaultSecurityGroupId(String region) {
String scoped = defaultSecurityGroupId(region);
String scoped = defaultSecurityGroupId(region, callerAccountId());
if (securityGroups.get(key(region, scoped)).isPresent()) {
return scoped;
}
// Legacy literals from before ids became region-scoped.
for (String legacy : List.of("sg-default", "sg-default-" + region)) {
// Legacy literals from before ids became account- and region-scoped.
for (String legacy : List.of("sg-" + Ec2Ids.stableHex("sg::" + region), "sg-default", "sg-default-" + region)) {
if (securityGroups.get(key(region, legacy)).isPresent()) {
return legacy;
}
@@ -83,8 +83,8 @@ class ApiGatewayV2AlbIntegrationTest {
.formParam("Name", "apigw-alb-test")
.formParam("Type", "application")
.formParam("Scheme", "internet-facing")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -39,7 +39,7 @@ class AutoScalingIntegrationTest {
.formParam("LaunchConfigurationName", "my-lc")
.formParam("ImageId", "ami-12345678")
.formParam("InstanceType", "t3.micro")
.formParam("SecurityGroups.member.1", Ec2Service.defaultSecurityGroupId("us-east-1"))
.formParam("SecurityGroups.member.1", Ec2Service.defaultSecurityGroupId("us-east-1", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -66,7 +66,7 @@ class CloudFormationEcsDeleteAfterRestoreIntegrationTest {
// in-memory RUNNING with no container behind it.
ecs("RunTask", "{\"cluster\":\"" + cluster + "\",\"taskDefinition\":\"" + family + "\",\"count\":1,"
+ "\"networkConfiguration\":{\"awsvpcConfiguration\":"
+ "{\"subnets\":[\"" + Ec2Service.defaultSubnetId("us-east-1", "a") + "\"]}}}");
+ "{\"subnets\":[\"" + Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000") + "\"]}}}");
deleteStack(stack);
@@ -423,7 +423,7 @@ class CloudFormationEcsForwardedSettingsIntegrationTest {
private static String serviceTemplate(String stackName, int desiredCount, String... settings) {
String declared = List.of(settings).stream().map(setting -> ", " + setting).collect(Collectors.joining());
return SERVICE_TEMPLATE.formatted(stackName, Ec2Service.defaultSubnetId("us-east-1", "a"), desiredCount, declared);
return SERVICE_TEMPLATE.formatted(stackName, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), desiredCount, declared);
}
private static void submitTemplate(String action, String stackName, String template) {
@@ -462,7 +462,7 @@ class CloudFormationEcsForwardedSettingsIntegrationTest {
/** Submits the template for {@code stackName}, with {@code maxPercent} as its MaxPercent when not null. */
private static void submit(String action, String stackName, String maxPercent) {
RequestSpecification request = cfn(action, stackName)
.formParam("TemplateBody", TEMPLATE.formatted(stackName, Ec2Service.defaultSubnetId("us-east-1", "a")));
.formParam("TemplateBody", TEMPLATE.formatted(stackName, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")));
if (maxPercent != null) {
request.formParam("Parameters.member.1.ParameterKey", "MaxPercent")
.formParam("Parameters.member.1.ParameterValue", maxPercent);
@@ -200,7 +200,7 @@ class CloudFormationEcsServiceStableIntegrationTest {
@Test
void updateStack_ecsServiceThatCannotStabilize_putsThePriorConfigurationBackOnRollback() {
String name = "cfn-stable-rb-" + Long.toString(System.nanoTime(), 36);
String subnet = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnet = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
stackCall("CreateStack", name, AWSVPC_TEMPLATE.formatted(name, 1, subnet));
CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE");
assertThat(stackStatus(name), equalTo("CREATE_COMPLETE"));
@@ -219,7 +219,7 @@ class CloudFormationEcsServiceStableIntegrationTest {
@Test
void updateStack_ecsServiceThatCannotStabilize_isReadBackWithoutTheDeploymentConfigurationItNeverHad() {
String name = "cfn-stable-dc-" + Long.toString(System.nanoTime(), 36);
String subnet = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnet = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
stackCall("CreateStack", name, AWSVPC_TEMPLATE.formatted(name, 1, subnet));
CfnStackWaits.awaitStatus(name, "CREATE_COMPLETE");
@@ -235,8 +235,8 @@ class CloudFormationEcsServiceStableIntegrationTest {
@Test
void createStack_awsvpcServiceWithSubnetListParameterUnderFnIf_usesEverySubnet() {
String name = "cfn-stable-list-" + Long.toString(System.nanoTime(), 36);
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnetB = Ec2Service.defaultSubnetId("us-east-1", "b");
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
String subnetB = Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000");
given()
.contentType("application/x-www-form-urlencoded")
@@ -155,7 +155,7 @@ class CloudFormationElbV2ListenerCertificateIntegrationTest {
"Https": %s,
"Other": %s%s
}, "Outputs": {"Https": {"Value": {"Ref": "Https"}}, "Other": {"Value": {"Ref": "Other"}}%s}}
""".formatted(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"),
""".formatted(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"),
listener(443, main), listener(8443, main), extra, extraOutput);
}
@@ -155,8 +155,8 @@ class CloudFormationElbV2ReplacementIntegrationTest {
void aReplacementOnOneSubnetFailsTheUpdateAndKeepsTheBalancer() {
String suffix = Long.toString(System.nanoTime(), 36);
String stackName = "elb-replace-one-" + suffix;
String subnetA = Ec2Service.defaultSubnetId(REGION, "a");
String subnetB = Ec2Service.defaultSubnetId(REGION, "b");
String subnetA = Ec2Service.defaultSubnetId(REGION, "a", "000000000000");
String subnetB = Ec2Service.defaultSubnetId(REGION, "b", "000000000000");
String template = """
{
"Resources": {
@@ -219,7 +219,7 @@ class CloudFormationElbV2ReplacementIntegrationTest {
"ListenerRef": {"Value": {"Ref": "Listener"}}
}
}
""".formatted(suffix, Ec2Service.defaultSubnetId(REGION, "a"), Ec2Service.defaultSubnetId(REGION, "b"));
""".formatted(suffix, Ec2Service.defaultSubnetId(REGION, "a", "000000000000"), Ec2Service.defaultSubnetId(REGION, "b", "000000000000"));
}
private static String template(String suffix, String listenerLb, String tgName, String extraResources) {
@@ -255,8 +255,8 @@ class CloudFormationElbV2ReplacementIntegrationTest {
"ListenerRef": {"Value": {"Ref": "Listener"}}
}
}
""".formatted(suffix, Ec2Service.defaultSubnetId(REGION, "a"), Ec2Service.defaultSubnetId(REGION, "b"),
tgName, Ec2Service.defaultVpcId(REGION), listenerLb, extraResources);
""".formatted(suffix, Ec2Service.defaultSubnetId(REGION, "a", "000000000000"), Ec2Service.defaultSubnetId(REGION, "b", "000000000000"),
tgName, Ec2Service.defaultVpcId(REGION, "000000000000"), listenerLb, extraResources);
}
private static void createStack(String stackName, String body) {
@@ -7755,9 +7755,9 @@ class CloudFormationIntegrationTest {
private static final String ECS_CONTENT_TYPE = "application/x-amz-json-1.1";
// The service's tasks must be able to start, since CloudFormation waits for them: an awsvpc
// task gets its ENI in a subnet and security group that exist, here the default VPC's.
private static final String ECS_SUBNET_A = Ec2Service.defaultSubnetId("us-east-1", "a");
private static final String ECS_SUBNET_B = Ec2Service.defaultSubnetId("us-east-1", "b");
private static final String ECS_SECURITY_GROUP = Ec2Service.defaultSecurityGroupId("us-east-1");
private static final String ECS_SUBNET_A = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
private static final String ECS_SUBNET_B = Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000");
private static final String ECS_SECURITY_GROUP = Ec2Service.defaultSecurityGroupId("us-east-1", "000000000000");
private static String outputValue(String describeXml, String key) {
return describeXml.split("<OutputKey>" + key + "</OutputKey>")[1]
@@ -8088,7 +8088,7 @@ class CloudFormationIntegrationTest {
}
}
}
""".formatted(groupName, Ec2Service.defaultVpcId("us-east-1"));
""".formatted(groupName, Ec2Service.defaultVpcId("us-east-1", "000000000000"));
given()
.formParam("Action", "CreateStack")
@@ -8306,8 +8306,8 @@ class CloudFormationIntegrationTest {
"RuleRef": { "Value": { "Ref": "Rule" } }
}
}
""".formatted(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"),
Ec2Service.defaultVpcId("us-east-1"));
""".formatted(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"),
Ec2Service.defaultVpcId("us-east-1", "000000000000"));
String stackName = "cfn-elbv2-stack";
@@ -8410,8 +8410,8 @@ class CloudFormationIntegrationTest {
@Test
void updateStack_elbV2Listener_modifiesPort() {
String stackName = "cfn-elbv2-update-stack";
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnetB = Ec2Service.defaultSubnetId("us-east-1", "b");
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
String subnetB = Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000");
String template = """
{
"Resources": {
@@ -8535,7 +8535,7 @@ class CloudFormationIntegrationTest {
}
}
}
""".formatted(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"));
""".formatted(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"));
given()
.contentType("application/x-www-form-urlencoded")
@@ -48,8 +48,8 @@ class CloudFormationRdsIntegrationTest {
"GroupName": {"Value": {"Ref": "DbSubnets"}}
}
}
""".formatted(groupName, Ec2Service.defaultSubnetId("us-east-1", "a"),
Ec2Service.defaultSubnetId("us-east-1", "b"));
""".formatted(groupName, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"),
Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"));
given()
.contentType("application/x-www-form-urlencoded")
@@ -199,8 +199,8 @@ class CloudFormationRdsIntegrationTest {
"ParameterGroupArn": {"Value": {"Fn::GetAtt": ["DbParams", "DBParameterGroupArn"]}}
}
}
""".formatted(subnetGroupName, Ec2Service.defaultSubnetId("us-east-1", "a"),
Ec2Service.defaultSubnetId("us-east-1", "b"), parameterGroupName);
""".formatted(subnetGroupName, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"),
Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"), parameterGroupName);
given()
.contentType("application/x-www-form-urlencoded")
@@ -262,7 +262,7 @@ class CloudFormationRdsIntegrationTest {
"GroupName": {"Value": {"Ref": "DbSubnets"}}
}
}
""".formatted(groupName, Ec2Service.defaultSubnetId("us-east-1", "a"),
Ec2Service.defaultSubnetId("us-east-1", "b"));
""".formatted(groupName, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"),
Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"));
}
}
@@ -39,8 +39,8 @@ class CodeDeployEcsIntegrationTest {
.formParam("Version", "2015-12-01")
.formParam("Name", "ecs-alb")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.when()
.post("/")
.then()
@@ -30,8 +30,8 @@ class DmsIntegrationTest {
private static final String ACCOUNT_ID = "723679240095";
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=" + ACCOUNT_ID + "/20260101/us-east-1/dms/aws4_request";
private static final String SUBNET_A = Ec2Service.defaultSubnetId("us-east-1", "a");
private static final String SUBNET_B = Ec2Service.defaultSubnetId("us-east-1", "b");
private static final String SUBNET_A = Ec2Service.defaultSubnetId("us-east-1", "a", ACCOUNT_ID);
private static final String SUBNET_B = Ec2Service.defaultSubnetId("us-east-1", "b", ACCOUNT_ID);
@BeforeAll
static void configureRestAssured() {
@@ -60,7 +60,7 @@ class DmsIntegrationTest {
.body("ReplicationSubnetGroups", hasSize(1))
.body("ReplicationSubnetGroups[0].ReplicationSubnetGroupDescription",
equalTo("terraform managed"))
.body("ReplicationSubnetGroups[0].VpcId", equalTo(Ec2Service.defaultVpcId("us-east-1")))
.body("ReplicationSubnetGroups[0].VpcId", equalTo(Ec2Service.defaultVpcId("us-east-1", ACCOUNT_ID)))
.body("ReplicationSubnetGroups[0].SubnetGroupStatus", equalTo("Complete"))
.body("ReplicationSubnetGroups[0].Subnets.SubnetIdentifier", contains(SUBNET_A, SUBNET_B))
.body("ReplicationSubnetGroups[0].Subnets.find { it.SubnetIdentifier == '"
@@ -156,8 +156,8 @@ class DmsIntegrationTest {
dms("CreateReplicationSubnetGroup", region)
.body("{\"ReplicationSubnetGroupIdentifier\":\"tf-default-probe\","
+ "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
+ "\"SubnetIds\":[\"" + Ec2Service.defaultSubnetId(region, "a") + "\",\""
+ Ec2Service.defaultSubnetId(region, "b") + "\"]}")
+ "\"SubnetIds\":[\"" + Ec2Service.defaultSubnetId(region, "a", ACCOUNT_ID) + "\",\""
+ Ec2Service.defaultSubnetId(region, "b", ACCOUNT_ID) + "\"]}")
.when()
.post("/")
.then()
@@ -204,7 +204,7 @@ class DmsIntegrationTest {
.statusCode(200)
.body("ReplicationSubnetGroups", hasSize(1))
.body("ReplicationSubnetGroups[0].ReplicationSubnetGroupIdentifier", equalTo("default"))
.body("ReplicationSubnetGroups[0].VpcId", equalTo(Ec2Service.defaultVpcId("ap-southeast-2")));
.body("ReplicationSubnetGroups[0].VpcId", equalTo(Ec2Service.defaultVpcId("ap-southeast-2", ACCOUNT_ID)));
}
/**
@@ -232,7 +232,7 @@ class DmsIntegrationTest {
.then()
.statusCode(200)
.body("ReplicationSubnetGroups", hasSize(1))
.body("ReplicationSubnetGroups[0].VpcId", equalTo(Ec2Service.defaultVpcId("ca-central-1")));
.body("ReplicationSubnetGroups[0].VpcId", equalTo(Ec2Service.defaultVpcId("ca-central-1", ACCOUNT_ID)));
}
@Test
@@ -32,8 +32,8 @@ class DmsLifecycleIntegrationTest {
private static final String ACCOUNT_ID = "723679240095";
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=" + ACCOUNT_ID + "/20260101/us-east-1/dms/aws4_request";
private static final String SUBNET_A = Ec2Service.defaultSubnetId("us-east-1", "a");
private static final String SUBNET_B = Ec2Service.defaultSubnetId("us-east-1", "b");
private static final String SUBNET_A = Ec2Service.defaultSubnetId("us-east-1", "a", ACCOUNT_ID);
private static final String SUBNET_B = Ec2Service.defaultSubnetId("us-east-1", "b", ACCOUNT_ID);
@BeforeAll
static void configureRestAssured() {
@@ -181,7 +181,7 @@ class DmsLifecycleIntegrationTest {
.body("ReplicationInstances[0].VpcSecurityGroups[0].VpcSecurityGroupId", equalTo("sg-1"))
.body("ReplicationInstances[0].ReplicationSubnetGroup.ReplicationSubnetGroupIdentifier",
equalTo("lc-rep-subnets"))
.body("ReplicationInstances[0].ReplicationSubnetGroup.VpcId", equalTo(Ec2Service.defaultVpcId("us-east-1")))
.body("ReplicationInstances[0].ReplicationSubnetGroup.VpcId", equalTo(Ec2Service.defaultVpcId("us-east-1", ACCOUNT_ID)))
.body("ReplicationInstances[0].EngineVersion", notNullValue());
dms("DeleteReplicationSubnetGroup")
@@ -232,7 +232,7 @@ class DmsLifecycleIntegrationTest {
describeInstance("lc-rep-default")
.body("ReplicationInstances[0].ReplicationSubnetGroup.ReplicationSubnetGroupIdentifier",
equalTo("default"))
.body("ReplicationInstances[0].ReplicationSubnetGroup.VpcId", equalTo(Ec2Service.defaultVpcId("us-east-1")))
.body("ReplicationInstances[0].ReplicationSubnetGroup.VpcId", equalTo(Ec2Service.defaultVpcId("us-east-1", ACCOUNT_ID)))
.body("ReplicationInstances[0].ReplicationSubnetGroup.SubnetGroupStatus", equalTo("Complete"))
.body("ReplicationInstances[0].ReplicationSubnetGroup.Subnets.SubnetIdentifier",
hasItems(SUBNET_A, SUBNET_B));
@@ -84,7 +84,7 @@ class DocDbClusterSnapshotServiceTest {
key.setKeyState("Enabled");
doReturn(key).when(kmsService).describeKey(KEY_ARN, "us-east-1");
Ec2Service ec2Service = mock(Ec2Service.class);
when(ec2Service.resolveDefaultSecurityGroupId(anyString())).thenAnswer(inv -> Ec2Service.defaultSecurityGroupId(inv.getArgument(0)));
when(ec2Service.resolveDefaultSecurityGroupId(anyString())).thenAnswer(inv -> Ec2Service.defaultSecurityGroupId(inv.getArgument(0), "000000000000"));
docDbService = new DocDbService(config, new RegionResolver("us-east-1", "000000000000"), containerManager,
storageFactory, mock(RdsService.class), ec2Service, kmsService);
}
@@ -68,7 +68,7 @@ class DocDbServiceTest {
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
rdsService = Mockito.mock(RdsService.class);
ec2Service = Mockito.mock(Ec2Service.class);
when(ec2Service.resolveDefaultSecurityGroupId(anyString())).thenAnswer(inv -> Ec2Service.defaultSecurityGroupId(inv.getArgument(0)));
when(ec2Service.resolveDefaultSecurityGroupId(anyString())).thenAnswer(inv -> Ec2Service.defaultSecurityGroupId(inv.getArgument(0), "000000000000"));
kmsService = Mockito.mock(KmsService.class);
when(kmsService.describeKey(any(), any())).thenThrow(new AwsException("NotFoundException", "Key not found", 404));
when(rdsService.isManagedClusterParameterGroup(any())).thenAnswer(inv ->
@@ -333,7 +333,7 @@ class DocDbServiceTest {
DocDbCluster stored = docDbService.getDbCluster("c1");
assertEquals("default", stored.getDbSubnetGroupName());
assertEquals("default.docdb5.0", stored.getDbClusterParameterGroupName());
assertEquals(List.of(Ec2Service.defaultSecurityGroupId("us-east-1")), stored.getVpcSecurityGroupIds());
assertEquals(List.of(Ec2Service.defaultSecurityGroupId("us-east-1", "000000000000")), stored.getVpcSecurityGroupIds());
assertFalse(stored.isStorageEncrypted());
assertNull(stored.getKmsKeyId());
assertEquals(1, stored.getBackupRetentionPeriod());
@@ -374,7 +374,7 @@ class DocDbServiceTest {
service.listDbClusters("arn:aws:rds:us-east-1:000000000000:cluster:old").iterator().next())) {
assertEquals("default", read.getDbSubnetGroupName());
assertEquals("default.docdb4.0", read.getDbClusterParameterGroupName());
assertEquals(List.of(Ec2Service.defaultSecurityGroupId("us-east-1")), read.getVpcSecurityGroupIds());
assertEquals(List.of(Ec2Service.defaultSecurityGroupId("us-east-1", "000000000000")), read.getVpcSecurityGroupIds());
assertEquals(1, read.getBackupRetentionPeriod());
assertEquals("04:00-06:00", read.getPreferredBackupWindow());
assertEquals("mon:00:00-mon:03:00", read.getPreferredMaintenanceWindow());
@@ -132,7 +132,7 @@ class Ec2CreateFleetIntegrationTest {
.formParam("LaunchTemplateConfig.1.LaunchTemplateSpecification.Version", "1")
.formParam("LaunchTemplateConfig.1.Overrides.1.InstanceType", "t3.micro")
.formParam("LaunchTemplateConfig.1.Overrides.1.ImageId", CONTRACT_IMAGE_ID)
.formParam("LaunchTemplateConfig.1.Overrides.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("LaunchTemplateConfig.1.Overrides.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("LaunchTemplateConfig.1.Overrides.1.AvailabilityZone", "us-east-1b")
.formParam("TargetCapacitySpecification.TotalTargetCapacity", "1")
.formParam("TargetCapacitySpecification.DefaultTargetCapacityType", "on-demand")
@@ -157,7 +157,7 @@ class Ec2CreateFleetIntegrationTest {
.formParam("LaunchTemplateConfig.1.LaunchTemplateSpecification.Version", "1")
.formParam("LaunchTemplateConfig.1.Overrides.1.InstanceType", "t3.micro")
.formParam("LaunchTemplateConfig.1.Overrides.1.ImageId", CONTRACT_IMAGE_ID)
.formParam("LaunchTemplateConfig.1.Overrides.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("LaunchTemplateConfig.1.Overrides.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.formParam("TargetCapacitySpecification.TotalTargetCapacity", "1")
.formParam("TargetCapacitySpecification.DefaultTargetCapacityType", "on-demand")
.header("Authorization", AUTH_HEADER)
@@ -167,9 +167,9 @@ class Ec2CreateFleetIntegrationTest {
.statusCode(200)
.body("CreateFleetResponse.fleetInstanceSet.item.availabilityZone", equalTo("us-east-1b"))
.body("CreateFleetResponse.fleetInstanceSet.item.subnetId",
equalTo(Ec2Service.defaultSubnetId("us-east-1", "b")))
equalTo(Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")))
.body("CreateFleetResponse.fleetInstanceSet.item.launchTemplateAndOverrides.overrides.subnetId",
equalTo(Ec2Service.defaultSubnetId("us-east-1", "b")))
equalTo(Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")))
.body("CreateFleetResponse.fleetInstanceSet.item.launchTemplateAndOverrides.overrides.availabilityZone",
equalTo("us-east-1b"));
}
@@ -105,7 +105,7 @@ class Ec2IntegrationTest {
.then()
.statusCode(200)
.contentType("application/xml")
.body("DescribeVpcsResponse.vpcSet.item[0].vpcId", equalTo(Ec2Service.defaultVpcId("us-east-1")))
.body("DescribeVpcsResponse.vpcSet.item[0].vpcId", equalTo(Ec2Service.defaultVpcId("us-east-1", "000000000000")))
.body("DescribeVpcsResponse.vpcSet.item[0].cidrBlock", equalTo("172.31.0.0/16"))
.body("DescribeVpcsResponse.vpcSet.item[0].isDefault", equalTo("true"));
}
@@ -119,7 +119,7 @@ class Ec2IntegrationTest {
given()
.formParam("Action", "DescribeSubnets")
.formParam("Filter.1.Name", "vpc-id")
.formParam("Filter.1.Value.1", Ec2Service.defaultVpcId("us-east-1"))
.formParam("Filter.1.Value.1", Ec2Service.defaultVpcId("us-east-1", "000000000000"))
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
@@ -144,7 +144,7 @@ class Ec2IntegrationTest {
.formParam("Filter.1.Name", "group-name")
.formParam("Filter.1.Value.1", "default")
.formParam("Filter.2.Name", "vpc-id")
.formParam("Filter.2.Value.1", Ec2Service.defaultVpcId("us-east-1"))
.formParam("Filter.2.Value.1", Ec2Service.defaultVpcId("us-east-1", "000000000000"))
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
@@ -154,7 +154,7 @@ class Ec2IntegrationTest {
.body("DescribeSecurityGroupsResponse.securityGroupInfo.item[0].groupName", equalTo("default"))
.body("DescribeSecurityGroupsResponse.securityGroupInfo.item[0].groupDescription",
equalTo("default VPC security group"))
.body("DescribeSecurityGroupsResponse.securityGroupInfo.item[0].vpcId", equalTo(Ec2Service.defaultVpcId("us-east-1")));
.body("DescribeSecurityGroupsResponse.securityGroupInfo.item[0].vpcId", equalTo(Ec2Service.defaultVpcId("us-east-1", "000000000000")));
}
// =========================================================================
@@ -2110,7 +2110,7 @@ class Ec2IntegrationTest {
given()
.formParam("Action", "DescribeSecurityGroupRules")
.formParam("Filter.1.Name", "group-id")
.formParam("Filter.1.Value.1", Ec2Service.defaultSecurityGroupId("us-east-1"))
.formParam("Filter.1.Value.1", Ec2Service.defaultSecurityGroupId("us-east-1", "000000000000"))
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
@@ -668,7 +668,7 @@ class Ec2QueryHandlerTest {
void aSecurityGroupDryRunWithoutAVpcIdNeedsTheDefaultVpcToExist() {
Ec2Service service = mock(Ec2Service.class);
when(service.requireSecurityGroupVpc("us-east-1", null)).thenThrow(new AwsException(
"InvalidVpcID.NotFound", "The vpc ID '" + Ec2Service.defaultVpcId("us-east-1") + "' does not exist", 400));
"InvalidVpcID.NotFound", "The vpc ID '" + Ec2Service.defaultVpcId("us-east-1", "000000000000") + "' does not exist", 400));
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
params.putSingle("GroupName", "test");
params.putSingle("GroupDescription", "test");
@@ -4504,8 +4504,8 @@ class Ec2ServiceTest {
assertNotEquals(usEastVpc.getVpcId(), euWestVpc.getVpcId(),
"default VPC id must differ per region");
assertEquals(Ec2Service.defaultVpcId("us-east-1"), usEastVpc.getVpcId());
assertEquals(Ec2Service.defaultVpcId("eu-west-1"), euWestVpc.getVpcId());
assertEquals(Ec2Service.defaultVpcId("us-east-1", "000000000000"), usEastVpc.getVpcId());
assertEquals(Ec2Service.defaultVpcId("eu-west-1", "000000000000"), euWestVpc.getVpcId());
List<String> usEastSubnetIds = service.describeSubnets("us-east-1", List.of(), Map.of()).stream()
.map(Subnet::getSubnetId).sorted().toList();
@@ -4515,9 +4515,9 @@ class Ec2ServiceTest {
assertTrue(usEastSubnetIds.stream().noneMatch(euWestSubnetIds::contains),
"default subnet ids must not collide across regions: " + usEastSubnetIds + " vs " + euWestSubnetIds);
assertEquals(List.of(
Ec2Service.defaultSubnetId("us-east-1", "a"),
Ec2Service.defaultSubnetId("us-east-1", "b"),
Ec2Service.defaultSubnetId("us-east-1", "c"))
Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"),
Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"),
Ec2Service.defaultSubnetId("us-east-1", "c", "000000000000"))
.stream().sorted().toList(),
usEastSubnetIds);
@@ -4528,8 +4528,8 @@ class Ec2ServiceTest {
assertNotEquals(usEastSg.getGroupId(), euWestSg.getGroupId(),
"default security group id must differ per region");
assertEquals(Ec2Service.defaultSecurityGroupId("us-east-1"), usEastSg.getGroupId());
assertEquals(Ec2Service.defaultSecurityGroupId("eu-west-1"), euWestSg.getGroupId());
assertEquals(Ec2Service.defaultSecurityGroupId("us-east-1", "000000000000"), usEastSg.getGroupId());
assertEquals(Ec2Service.defaultSecurityGroupId("eu-west-1", "000000000000"), euWestSg.getGroupId());
}
@Test
@@ -4580,6 +4580,57 @@ class Ec2ServiceTest {
assertEquals(usEastIds, defaultResourceIds(service2, "us-east-1"));
}
@Test
void defaultNetworkResourceIdsAreUniquePerAccountInSameRegion() {
RequestContext context = new RequestContext();
Ec2Service service = mockedVpcNetworkService(context, Map.of(), null);
context.setAccountId("000000000000");
Vpc firstVpc = service.describeVpcs("us-east-1", List.of(), Map.of()).getFirst();
List<Subnet> firstSubnets = service.describeSubnets("us-east-1", List.of(), Map.of());
List<String> firstSubnetIds = firstSubnets.stream().map(Subnet::getSubnetId).sorted().toList();
SecurityGroup firstSg = service.describeSecurityGroups("us-east-1", List.of(), List.of("default"), Map.of())
.getFirst();
List<String> firstOtherIds = defaultResourceIds(service, "us-east-1");
context.setAccountId("111122223333");
Vpc secondVpc = service.describeVpcs("us-east-1", List.of(), Map.of()).getFirst();
List<Subnet> secondSubnets = service.describeSubnets("us-east-1", List.of(), Map.of());
List<String> secondSubnetIds = secondSubnets.stream().map(Subnet::getSubnetId).sorted().toList();
SecurityGroup secondSg = service.describeSecurityGroups("us-east-1", List.of(), List.of("default"), Map.of())
.getFirst();
List<String> secondOtherIds = defaultResourceIds(service, "us-east-1");
assertEquals("000000000000", firstVpc.getOwnerId());
assertTrue(firstSubnets.stream().allMatch(s -> "000000000000".equals(s.getOwnerId())));
assertEquals("000000000000", firstSg.getOwnerId());
assertEquals("111122223333", secondVpc.getOwnerId());
assertTrue(secondSubnets.stream().allMatch(s -> "111122223333".equals(s.getOwnerId())));
assertEquals("111122223333", secondSg.getOwnerId());
assertNotEquals(firstVpc.getVpcId(), secondVpc.getVpcId(),
"default VPC id must differ per account in the same region");
assertEquals(Ec2Service.defaultVpcId("us-east-1", "000000000000"), firstVpc.getVpcId());
assertEquals(Ec2Service.defaultVpcId("us-east-1", "111122223333"), secondVpc.getVpcId());
assertEquals(secondVpc.getVpcId(), service.resolveDefaultVpcId("us-east-1"));
assertTrue(firstSubnetIds.stream().noneMatch(secondSubnetIds::contains),
"default subnet ids must not collide across accounts: " + firstSubnetIds + " vs " + secondSubnetIds);
assertNotEquals(firstSg.getGroupId(), secondSg.getGroupId(),
"default security group id must differ per account in the same region");
assertEquals(Ec2Service.defaultSecurityGroupId("us-east-1", "000000000000"), firstSg.getGroupId());
assertEquals(Ec2Service.defaultSecurityGroupId("us-east-1", "111122223333"), secondSg.getGroupId());
assertEquals(secondSg.getGroupId(), service.resolveDefaultSecurityGroupId("us-east-1"));
assertTrue(firstOtherIds.stream().noneMatch(secondOtherIds::contains),
"default resource ids must not collide across accounts: " + firstOtherIds + " vs " + secondOtherIds);
assertEquals(Ec2Service.defaultInternetGatewayId("us-east-1", "000000000000"), firstOtherIds.get(0));
assertEquals(Ec2Service.defaultRouteTableId("us-east-1", "000000000000"), firstOtherIds.get(1));
assertEquals(Ec2Service.defaultRouteTableAssociationId("us-east-1", "000000000000"), firstOtherIds.get(2));
assertEquals(Ec2Service.defaultNetworkAclId("us-east-1", "000000000000"), firstOtherIds.get(3));
assertEquals(Ec2Service.defaultNetworkAclAssociationId("us-east-1",
Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), "000000000000"), firstOtherIds.get(4));
}
/** Every default resource id of one region, in a fixed order: gateway, route table, its
* first association, the default ACL, its first association and the VPC CIDR association. */
private static List<String> defaultResourceIds(Ec2Service service, String region) {
@@ -4636,7 +4687,7 @@ class Ec2ServiceTest {
// A genuinely fresh region has neither format on file, so the resolver falls back to the
// scoped form ensureDefaultResources would seed.
assertEquals(Ec2Service.defaultVpcId("eu-west-1"), service.resolveDefaultVpcId("eu-west-1"));
assertEquals(Ec2Service.defaultVpcId("eu-west-1", "000000000000"), service.resolveDefaultVpcId("eu-west-1"));
}
@SuppressWarnings("unchecked")
@@ -4655,11 +4706,11 @@ class Ec2ServiceTest {
mock(AmiImageResolver.class), mock(Ec2ImageCatalog.class), new Ec2InstanceTypeCatalog(),
new InMemoryStorageFactory());
String subnetId = service.describeSubnets("us-east-1", List.of(),
Map.of("vpc-id", List.of(Ec2Service.defaultVpcId("us-east-1")))).getFirst().getSubnetId();
VpcEndpoint endpoint = service.createVpcEndpoint("us-east-1", Ec2Service.defaultVpcId("us-east-1"),
Map.of("vpc-id", List.of(Ec2Service.defaultVpcId("us-east-1", "000000000000")))).getFirst().getSubnetId();
VpcEndpoint endpoint = service.createVpcEndpoint("us-east-1", Ec2Service.defaultVpcId("us-east-1", "000000000000"),
"com.amazonaws.us-east-1.s3", "Interface",
List.of(), List.of(subnetId), List.of(), null, null, List.of());
service.createVpcEndpoint("us-east-1", Ec2Service.defaultVpcId("us-east-1"),
service.createVpcEndpoint("us-east-1", Ec2Service.defaultVpcId("us-east-1", "000000000000"),
"com.amazonaws.us-east-1.dynamodb", "Gateway",
List.of(), List.of(), List.of(), null, null, List.of());
@@ -4668,7 +4719,7 @@ class Ec2ServiceTest {
assertEquals(1, enis.size(), "only Interface endpoints have ENIs");
NetworkInterface eni = enis.getFirst();
assertEquals(subnetId, eni.getSubnetId());
assertEquals(Ec2Service.defaultVpcId("us-east-1"), eni.getVpcId());
assertEquals(Ec2Service.defaultVpcId("us-east-1", "000000000000"), eni.getVpcId());
assertEquals("VPC Endpoint Interface " + endpoint.getVpcEndpointId(), eni.getDescription());
assertTrue(eni.getNetworkInterfaceId().startsWith("eni-"));
@@ -5111,7 +5162,7 @@ class Ec2ServiceTest {
// An interface created with its own address takes no lease on the VPC network, so deleting
// it leaves nothing behind that would keep automatic allocation off the address.
Ec2Service service = realVpcNetworkService(new RequestContext());
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
service.describeSubnets("us-east-1", List.of(), Map.of());
String first = service.createNetworkInterface("us-east-1", subnetId, null, null,
List.of(), List.of(), List.of()).getPrivateIpAddress();
@@ -5269,7 +5320,7 @@ class Ec2ServiceTest {
RequestContext context = new RequestContext();
RealVpcNetworkFixture fixture = realVpcNetworkFixture(context, Map.of());
Ec2Service service = fixture.service();
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "111122223333");
context.setAccountId("111122223333");
service.describeSubnets("us-east-1", List.of(), Map.of());
String stale = fixture.vpcNetworks().allocatePrivateIp("111122223333", "us-east-1", subnetId).orElseThrow();
@@ -5281,19 +5332,20 @@ class Ec2ServiceTest {
@ParameterizedTest
@ValueSource(strings = {"instance", "network-interface", "nat-gateway"})
void aRequestedPrivateIpAnotherAccountHoldsOnItsOwnDefaultVpcIsFreeInThisOne(String holder) {
// Default VPC and subnet ids are the same in every account, but each account's VPC has its own
// Docker network and lease table, as each account's VPC is its own on AWS: what the other
// account holds on its network does not hold this account's address.
// Each account's default VPC has its own Docker network and lease table, as each account's
// VPC is its own on AWS: what the other account holds on its network does not hold this
// account's address.
RequestContext context = new RequestContext();
Ec2Service service = realVpcNetworkService(context);
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a");
String otherSubnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "111122223333");
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
context.setAccountId("111122223333");
service.describeSubnets("us-east-1", List.of(), Map.of());
String held = switch (holder) {
case "instance" -> launchAddresses(service, subnetId, 1).getFirst();
case "network-interface" -> service.createNetworkInterface("us-east-1", subnetId, "holder", null,
case "instance" -> launchAddresses(service, otherSubnetId, 1).getFirst();
case "network-interface" -> service.createNetworkInterface("us-east-1", otherSubnetId, "holder", null,
List.of(), List.of(), List.of()).getPrivateIpAddress();
default -> service.createNatGateway("us-east-1", subnetId, null, "private", List.of())
default -> service.createNatGateway("us-east-1", otherSubnetId, null, "private", List.of())
.getNatGatewayAddresses().getFirst().getPrivateIp();
};
assertEquals("172.31.0.10", held, "the first address of the other account's network");
@@ -5309,10 +5361,11 @@ class Ec2ServiceTest {
// The other account's interface holds the address on that account's network alone.
RequestContext context = new RequestContext();
Ec2Service service = realVpcNetworkService(context);
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a");
String otherSubnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "111122223333");
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
context.setAccountId("111122223333");
service.describeSubnets("us-east-1", List.of(), Map.of());
service.createNetworkInterface("us-east-1", subnetId, "holder", "172.31.0.50",
service.createNetworkInterface("us-east-1", otherSubnetId, "holder", "172.31.0.50",
List.of(), List.of(), List.of());
context.setAccountId("000000000000");
@@ -5325,7 +5378,7 @@ class Ec2ServiceTest {
void anotherAccountsNatGatewayDoesNotHoldThisAccountsAddressAfterARestart() {
// The other account's persisted NAT gateway holds its address in that account's default VPC,
// whose network is its own.
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
NatGatewayAddress address = new NatGatewayAddress();
address.setPrivateIp("172.31.0.10");
NatGateway natGateway = new NatGateway();
@@ -5347,7 +5400,7 @@ class Ec2ServiceTest {
void anotherAccountsInstanceOutsideASubstitutedRangeDoesNotHoldTheRequestedPrivateIp() {
// A substituted subnet never leases an address outside its effective range, so no
// container holds it on the shared network and each account keeps it as it would on AWS.
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
AccountAwareStorageBackend<Instance> instanceStore = AccountAwareStorageBackend.inMemory("000000000000");
instanceStore.putForAccount("111122223333", "us-east-1::i-other",
defaultSubnetInstance("i-other", "172.31.0.50", InstanceState.running()));
@@ -5432,10 +5485,11 @@ class Ec2ServiceTest {
// account's own default VPC network hands the same address out.
RequestContext context = new RequestContext();
Ec2Service service = realVpcNetworkService(context);
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a");
String otherSubnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "111122223333");
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
context.setAccountId("111122223333");
service.describeSubnets("us-east-1", List.of(), Map.of());
service.createNetworkInterface("us-east-1", subnetId, "holder", "172.31.0.10",
service.createNetworkInterface("us-east-1", otherSubnetId, "holder", "172.31.0.10",
List.of(), List.of(), List.of());
context.setAccountId("000000000000");
@@ -5557,10 +5611,11 @@ class Ec2ServiceTest {
RequestContext context = new RequestContext();
VpcNetworkManager vpcNetworks = mock(VpcNetworkManager.class);
Ec2Service service = mockedVpcNetworkService(context, Map.of(), vpcNetworks);
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a");
String otherSubnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "111122223333");
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
context.setAccountId("111122223333");
service.describeSubnets("us-east-1", List.of(), Map.of());
service.createNetworkInterface("us-east-1", subnetId, "holder", "172.31.0.10",
service.createNetworkInterface("us-east-1", otherSubnetId, "holder", "172.31.0.10",
List.of(), List.of(), List.of());
when(vpcNetworks.allocatePrivateIp("000000000000", "us-east-1", subnetId))
.thenReturn(Optional.of("172.31.0.10"), Optional.empty());
@@ -5575,7 +5630,7 @@ class Ec2ServiceTest {
RequestContext context = new RequestContext();
VpcNetworkManager vpcNetworks = mock(VpcNetworkManager.class);
Ec2Service service = mockedVpcNetworkService(context, Map.of(), vpcNetworks);
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
service.describeSubnets("us-east-1", List.of(), Map.of());
service.createNetworkInterface("us-east-1", subnetId, "holder", "172.31.0.10",
List.of(), List.of(), List.of());
@@ -5590,7 +5645,7 @@ class Ec2ServiceTest {
void anAddressAContainerLeasedIsInUseUntilItIsGivenBack() {
VpcNetworkManager vpcNetworks = mock(VpcNetworkManager.class);
Ec2Service service = mockedVpcNetworkService(new RequestContext(), Map.of(), vpcNetworks);
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnetId = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
service.describeSubnets("us-east-1", List.of(), Map.of());
when(vpcNetworks.allocatePrivateIp("000000000000", "us-east-1", subnetId))
.thenReturn(Optional.of("172.31.0.10"), Optional.empty());
@@ -5771,8 +5826,8 @@ class Ec2ServiceTest {
private static Instance defaultSubnetInstance(String instanceId, String privateIp, InstanceState state) {
Instance instance = persistedInstance(instanceId, privateIp, state);
instance.setVpcId(Ec2Service.defaultVpcId("us-east-1"));
instance.setSubnetId(Ec2Service.defaultSubnetId("us-east-1", "a"));
instance.setVpcId(Ec2Service.defaultVpcId("us-east-1", "000000000000"));
instance.setSubnetId(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"));
return instance;
}
@@ -5974,7 +6029,7 @@ class Ec2ServiceTest {
mock(Ec2PortForwardManager.class),
mock(AmiImageResolver.class), mock(Ec2ImageCatalog.class), new Ec2InstanceTypeCatalog(),
new InMemoryStorageFactory());
SecurityGroup web = service.createSecurityGroup("us-east-1", "web", "web sg", Ec2Service.defaultVpcId("us-east-1"));
SecurityGroup web = service.createSecurityGroup("us-east-1", "web", "web sg", Ec2Service.defaultVpcId("us-east-1", "000000000000"));
Reservation reservation = service.runInstances("us-east-1", "ami-1234567890abcdef0", "t3.micro",
1, 1, null, List.of(), null, null, List.of(), null, null);
String instanceId = reservation.getInstances().getFirst().getInstanceId();
@@ -43,7 +43,7 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
class EcsAwsvpcTaskAddressDockerIntegrationTest {
private static final String REGION = "us-east-1";
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a");
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
private static final int PORT = 8080;
/**
@@ -58,7 +58,7 @@ class EcsContainerInsightsIntegrationTest {
"Cluster": {"Ref": "Cluster"}, "TaskDefinition": {"Ref": "TaskDef"},
"DesiredCount": 1, "LaunchType": "FARGATE", "NetworkConfiguration": {"AwsvpcConfiguration":
{"Subnets": ["%2$s"]}}}}}}
""".formatted(cluster, Ec2Service.defaultSubnetId("us-east-1", "a"));
""".formatted(cluster, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"));
given().contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateStack")
@@ -119,7 +119,7 @@ class EcsDescribeServicesIntegrationTest {
"taskDefinition":"blue-running-task","desiredCount":1,"launchType":"FARGATE",
"networkConfiguration":{"awsvpcConfiguration":{"subnets":["%s"]}},
"deploymentController":{"type":"CODE_DEPLOY"}}
""".formatted(Ec2Service.defaultSubnetId("us-east-1", "a")));
""".formatted(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")));
String primaryId = created.path("service.taskSets[0].id");
await().atMost(Duration.ofSeconds(30)).untilAsserted(() ->
describe("blue-running-cluster", "blue-running-service").then()
@@ -41,7 +41,7 @@ class EcsExecuteCommandIntegrationTest {
private static final String CLUSTER = "exec-cluster";
private static final String NETWORK =
"\"networkConfiguration\":{\"awsvpcConfiguration\":{\"subnets\":"
+ "[\"" + Ec2Service.defaultSubnetId("us-east-1", "a") + "\"]}}";
+ "[\"" + Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000") + "\"]}}";
@BeforeAll
static void configure() {
@@ -38,7 +38,7 @@ class EcsFargateEdgeCaseIntegrationTest {
private static final String CLUSTER = "fargate-edge-cluster";
private static final String NETWORK =
"\"networkConfiguration\":{\"awsvpcConfiguration\":{\"subnets\":"
+ "[\"" + Ec2Service.defaultSubnetId("us-east-1", "a") + "\"]}}";
+ "[\"" + Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000") + "\"]}}";
@BeforeAll
static void configure() {
@@ -447,7 +447,7 @@ class EcsFargateEdgeCaseIntegrationTest {
call("RunTask", "{\"cluster\":\"" + CLUSTER + "\",\"taskDefinition\":\"" + family
+ "\",\"launchType\":\"FARGATE\",\"networkConfiguration\":{\"awsvpcConfiguration\":"
+ "{\"subnets\":[\"" + Ec2Service.defaultSubnetId("us-east-1", "a") + "\"],\"securityGroups\":[\"sg-nope\"]}}}", 400)
+ "{\"subnets\":[\"" + Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000") + "\"],\"securityGroups\":[\"sg-nope\"]}}}", 400)
.then()
.body("__type", containsString("InvalidParameterException"))
.body("message", containsString("sg-nope"));
@@ -779,7 +779,7 @@ class EcsFargateEdgeCaseIntegrationTest {
// A changed network configuration starts new tasks, so it rolls.
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-roll-svc\","
+ "\"networkConfiguration\":{\"awsvpcConfiguration\":{\"subnets\":"
+ "[\"" + Ec2Service.defaultSubnetId("us-east-1", "b") + "\"]}}}", 200);
+ "[\"" + Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000") + "\"]}}}", 200);
assertNotEquals(initial, deploymentId("edge-roll-svc"),
"a changed network configuration must roll the deployment");
@@ -1071,7 +1071,7 @@ class EcsFargateEdgeCaseIntegrationTest {
+ "\"launchType\":\"FARGATE\",\"externalId\":\"d-EXAMPLE\","
+ "\"scale\":{\"value\":50,\"unit\":\"PERCENT\"},"
+ "\"networkConfiguration\":{\"awsvpcConfiguration\":{\"subnets\":"
+ "[\"" + Ec2Service.defaultSubnetId("us-east-1", "a") + "\"]}},"
+ "[\"" + Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000") + "\"]}},"
+ "\"loadBalancers\":[{\"targetGroupArn\":\"arn:aws:elasticloadbalancing:us-east-1:"
+ "000000000000:targetgroup/tg/1\",\"containerName\":\"app\",\"containerPort\":80}],"
+ "\"tags\":[{\"key\":\"team\",\"value\":\"platform\"}]}", 200);
@@ -32,7 +32,7 @@ class EcsFargateTaskIntegrationTest {
private static final String TARGET = "AmazonEC2ContainerServiceV20141113.";
private static final String CT = "application/x-amz-json-1.1";
private static final String CLUSTER = "fargate-task-cluster";
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a");
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
private static final String NETWORK =
"\"networkConfiguration\":{\"awsvpcConfiguration\":{\"subnets\":[\"" + SUBNET + "\"]}}";
@@ -461,7 +461,7 @@ class EcsIntegrationTest {
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}},
"count": 1
}
""".formatted(CLUSTER_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a")))
""".formatted(CLUSTER_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.when()
.post("/")
.then()
@@ -551,7 +551,7 @@ class EcsIntegrationTest {
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}},
"count": 1
}
""".formatted(CLUSTER_NAME, Ec2Service.defaultSubnetId("us-east-1", "a")))
""".formatted(CLUSTER_NAME, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.when()
.post("/")
.then()
@@ -708,7 +708,7 @@ class EcsIntegrationTest {
{"key": "Project", "value": "project1"}
]
}
""".formatted(CLUSTER_NAME, SERVICE_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a")))
""".formatted(CLUSTER_NAME, SERVICE_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.when()
.post("/")
.then()
@@ -799,7 +799,7 @@ class EcsIntegrationTest {
"launchType": "FARGATE",
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}}
}
""".formatted(CLUSTER_NAME, SERVICE_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a")))
""".formatted(CLUSTER_NAME, SERVICE_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.when()
.post("/")
.then()
@@ -821,7 +821,7 @@ class EcsIntegrationTest {
"launchType": "FARGATE",
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}}
}
""".formatted(CLUSTER_NAME, SERVICE_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a")))
""".formatted(CLUSTER_NAME, SERVICE_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.when()
.post("/")
.then()
@@ -845,7 +845,7 @@ class EcsIntegrationTest {
"launchType": "FARGATE",
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}}
}
""".formatted(CLUSTER_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a")))
""".formatted(CLUSTER_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.when()
.post("/")
.then()
@@ -888,7 +888,7 @@ class EcsIntegrationTest {
"launchType": "FARGATE",
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}}
}
""".formatted(CLUSTER_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a")))
""".formatted(CLUSTER_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.when()
.post("/")
.then()
@@ -1115,7 +1115,7 @@ class EcsIntegrationTest {
"launchType": "FARGATE",
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}}
}
""".formatted(REVIEW_CLUSTER, REVIEW_SERVICE, Ec2Service.defaultSubnetId("us-east-1", "a")))
""".formatted(REVIEW_CLUSTER, REVIEW_SERVICE, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.when()
.post("/")
.then()
@@ -1208,7 +1208,7 @@ class EcsIntegrationTest {
}
]
}
""".formatted(REVIEW_CLUSTER, REVIEW_LB_SERVICE, Ec2Service.defaultSubnetId("us-east-1", "a")))
""".formatted(REVIEW_CLUSTER, REVIEW_LB_SERVICE, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.when()
.post("/")
.then()
@@ -1233,7 +1233,7 @@ class EcsIntegrationTest {
}
]
}
""".formatted(REVIEW_CLUSTER, REVIEW_LB_SERVICE, Ec2Service.defaultSubnetId("us-east-1", "a")))
""".formatted(REVIEW_CLUSTER, REVIEW_LB_SERVICE, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.when()
.post("/")
.then()
@@ -61,7 +61,7 @@ class EcsSecurityGroupTaskRoleDockerIntegrationTest {
private static final Logger LOG = Logger.getLogger(EcsSecurityGroupTaskRoleDockerIntegrationTest.class);
private static final String REGION = "us-east-1";
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a");
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
private static final String NETWORK = "floci-ecs-sg-task-role-it";
private static final int CREDENTIALS_PORT = freePort();
@@ -49,7 +49,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class EcsServiceDiscoveryDockerIntegrationTest {
private static final String REGION = "us-east-1";
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a");
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
private static final String BUSYBOX_IMAGE = TestImages.BUSYBOX;
private static final String CONTAINER_NAME = "app";
private static final String CLOUD_MAP_SERVICE_NAME = "cache";
@@ -207,7 +207,7 @@ class EcsServicePersistenceTest {
/** An awsvpc service needs the subnets its tasks get an ENI in, as it does on AWS. */
private static NetworkConfiguration awsvpcConfiguration() {
AwsVpcConfiguration awsvpc = new AwsVpcConfiguration();
awsvpc.setSubnets(List.of(Ec2Service.defaultSubnetId(REGION, "a")));
awsvpc.setSubnets(List.of(Ec2Service.defaultSubnetId(REGION, "a", "000000000000")));
NetworkConfiguration networkConfiguration = new NetworkConfiguration();
networkConfiguration.setAwsvpcConfiguration(awsvpc);
return networkConfiguration;
@@ -142,7 +142,7 @@ class EcsServicePlatformVersionIntegrationTest {
CreateServiceRequest.Builder request = CreateServiceRequest.builder().cluster(cluster).serviceName(SERVICE)
.taskDefinition(taskDefinition).desiredCount(desiredCount).platformVersion(platformVersion)
.networkConfiguration(NetworkConfiguration.builder().awsvpcConfiguration(network -> network
.subnets(Ec2Service.defaultSubnetId("us-east-1", "a"))).build());
.subnets(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))).build());
if (provider == null) {
request.launchType("FARGATE");
} else {
@@ -48,7 +48,7 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
class EcsSharedTaskNetworkDockerIntegrationTest {
private static final String REGION = "us-east-1";
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a");
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
private static final int FRONT_PORT = 8080;
private static final int BACKEND_PORT = 8081;
@@ -79,7 +79,7 @@ class EcsTaskMetadataControllerTest {
private static Subnet subnet() {
Subnet subnet = new Subnet();
subnet.setSubnetId(Ec2Service.defaultSubnetId("us-east-1", "a"));
subnet.setSubnetId(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"));
subnet.setVpcId("vpc-0a1b2c3d");
subnet.setCidrBlock("172.31.32.0/20");
subnet.setAvailabilityZone("us-east-1a");
@@ -116,7 +116,7 @@ class EcsTaskMetadataControllerTest {
task.setPrivateDnsName("ip-172-31-0-42.ec2.internal");
AwsVpcConfiguration awsvpc = new AwsVpcConfiguration();
awsvpc.setSubnets(List.of(Ec2Service.defaultSubnetId("us-east-1", "a")));
awsvpc.setSubnets(List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")));
NetworkConfiguration networkConfiguration = new NetworkConfiguration();
networkConfiguration.setAwsvpcConfiguration(awsvpc);
task.setNetworkConfiguration(networkConfiguration);
@@ -817,8 +817,8 @@ class EksServiceTest {
new EksOidcService(storageFactory, new ObjectMapper()), mock(EksAccessEntryService.class));
ResourcesVpcConfig vpcConfig = new ResourcesVpcConfig();
vpcConfig.setSubnetIds(List.of(Ec2Service.defaultSubnetId("us-east-1", "a"),
Ec2Service.defaultSubnetId("us-east-1", "b")));
vpcConfig.setSubnetIds(List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"),
Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
CreateClusterRequest req = new CreateClusterRequest();
req.setName("real-subnet-cluster");
@@ -828,8 +828,8 @@ class EksServiceTest {
Cluster cluster = service.createCluster(req);
assertEquals("real-subnet-cluster", cluster.getName());
assertEquals(List.of(Ec2Service.defaultSubnetId("us-east-1", "a"),
Ec2Service.defaultSubnetId("us-east-1", "b")),
assertEquals(List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"),
Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")),
cluster.getResourcesVpcConfig().getSubnetIds());
}
@@ -852,8 +852,8 @@ class EksServiceTest {
realEc2Service(), new EksOidcService(storageFactory, new ObjectMapper()), mock(EksAccessEntryService.class));
ResourcesVpcConfig vpcConfig = new ResourcesVpcConfig();
vpcConfig.setSubnetIds(List.of(Ec2Service.defaultSubnetId("us-east-1", "a"),
Ec2Service.defaultSubnetId("us-east-1", "b")));
vpcConfig.setSubnetIds(List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"),
Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
CreateClusterRequest req = new CreateClusterRequest();
req.setName("vpc-id-cluster");
@@ -862,7 +862,7 @@ class EksServiceTest {
Cluster cluster = service.createCluster(req);
assertEquals(Ec2Service.defaultVpcId("us-east-1"), cluster.getResourcesVpcConfig().getVpcId());
assertEquals(Ec2Service.defaultVpcId("us-east-1", "000000000000"), cluster.getResourcesVpcConfig().getVpcId());
}
@Test
@@ -882,7 +882,7 @@ class EksServiceTest {
realEc2Service(), new EksOidcService(storageFactory, new ObjectMapper()), mock(EksAccessEntryService.class));
ResourcesVpcConfig vpcConfig = new ResourcesVpcConfig();
vpcConfig.setSubnetIds(List.of(Ec2Service.defaultSubnetId("eu-west-2", "a")));
vpcConfig.setSubnetIds(List.of(Ec2Service.defaultSubnetId("eu-west-2", "a", "000000000000")));
CreateClusterRequest req = new CreateClusterRequest();
req.setName("cross-region-cluster");
@@ -920,7 +920,7 @@ class EksServiceTest {
Ec2Service ec2Service = realEc2Service();
ec2Service.ensureDefaultResources("us-east-1");
String usEastOnlySubnet = ec2Service
.createSubnet("us-east-1", Ec2Service.defaultVpcId("us-east-1"), "172.31.200.0/24", "us-east-1a")
.createSubnet("us-east-1", Ec2Service.defaultVpcId("us-east-1", "000000000000"), "172.31.200.0/24", "us-east-1a")
.getSubnetId();
// The request is for eu-west-2, where that subnet does not exist.
@@ -1982,7 +1982,7 @@ class EksServiceTest {
void createClusterCreatesClusterSecurityGroupInResolvedVpc() {
Ec2Service ec2Service = realEc2Service();
ec2Service.ensureDefaultResources("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1", "000000000000");
String subnetId = ec2Service
.createSubnet("us-east-1", defaultVpc, "172.31.100.0/24", "us-east-1a")
.getSubnetId();
@@ -2109,7 +2109,7 @@ class EksServiceTest {
void deleteClusterDeletesClusterSecurityGroup() {
Ec2Service ec2Service = realEc2Service();
ec2Service.ensureDefaultResources("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1", "000000000000");
String subnetId = ec2Service
.createSubnet("us-east-1", defaultVpc, "172.31.101.0/24", "us-east-1a")
.getSubnetId();
@@ -2139,7 +2139,7 @@ class EksServiceTest {
void deleteClusterSucceedsWhenClusterSecurityGroupAlreadyDeleted() {
Ec2Service ec2Service = realEc2Service();
ec2Service.ensureDefaultResources("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1", "000000000000");
String subnetId = ec2Service
.createSubnet("us-east-1", defaultVpc, "172.31.102.0/24", "us-east-1a")
.getSubnetId();
@@ -2200,7 +2200,7 @@ class EksServiceTest {
void backfillClusterSecurityGroupOnStartup() {
Ec2Service ec2Service = realEc2Service();
ec2Service.ensureDefaultResources("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1", "000000000000");
StorageBackend<String, Cluster> rawClusters = new InMemoryStorage<>();
AccountAwareStorageBackend<Cluster> clusterStore =
@@ -2239,7 +2239,7 @@ class EksServiceTest {
void backfillClusterSecurityGroupLeavesExistingSecurityGroupUnchanged() {
Ec2Service ec2Service = realEc2Service();
ec2Service.ensureDefaultResources("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1", "000000000000");
StorageBackend<String, Cluster> rawClusters = new InMemoryStorage<>();
AccountAwareStorageBackend<Cluster> clusterStore =
@@ -2270,7 +2270,7 @@ class EksServiceTest {
void restartRoundTripPersistsClusterSecurityGroupId() {
Ec2Service ec2Service = realEc2Service();
ec2Service.ensureDefaultResources("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1", "000000000000");
String subnetId = ec2Service
.createSubnet("us-east-1", defaultVpc, "172.31.103.0/24", "us-east-1a")
.getSubnetId();
@@ -2338,7 +2338,7 @@ class EksServiceTest {
void createClusterCleansUpSecurityGroupWhenClusterCreationFails() {
Ec2Service ec2Service = realEc2Service();
ec2Service.ensureDefaultResources("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1", "000000000000");
String subnetId = ec2Service
.createSubnet("us-east-1", defaultVpc, "172.31.104.0/24", "us-east-1a")
.getSubnetId();
@@ -2373,7 +2373,7 @@ class EksServiceTest {
void backfillClusterSecurityGroupsSkipsMissingVpcWithoutFailingStartup() {
Ec2Service ec2Service = realEc2Service();
ec2Service.ensureDefaultResources("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1", "000000000000");
StorageBackend<String, Cluster> rawClusters = new InMemoryStorage<>();
AccountAwareStorageBackend<Cluster> clusterStore =
@@ -2418,7 +2418,7 @@ class EksServiceTest {
String nonDefaultAccount = "123456789012";
Ec2Service ec2Service = realEc2Service();
ec2Service.ensureDefaultResources("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1", "000000000000");
StorageBackend<String, Cluster> rawClusters = new InMemoryStorage<>();
AccountAwareStorageBackend<Cluster> clusterStore =
@@ -2453,7 +2453,7 @@ class EksServiceTest {
void createClusterSecurityGroupCleansUpWhenTaggingFails() {
Ec2Service spyEc2 = spy(realEc2Service());
spyEc2.ensureDefaultResources("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1");
String defaultVpc = Ec2Service.defaultVpcId("us-east-1", "000000000000");
doThrow(new RuntimeException("Simulated tagging failure"))
.when(spyEc2).createSystemTags(any(), any(), any());
@@ -60,7 +60,7 @@ class ElbClassicCertificateDeleteRaceTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Version", CLASSIC_VERSION)
.formParam("LoadBalancerName", lbName)
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Listeners.member.1.Protocol", "HTTPS")
.formParam("Listeners.member.1.LoadBalancerPort", "443")
.formParam("Listeners.member.1.InstanceProtocol", "HTTP")
@@ -43,7 +43,7 @@ class ElbClassicIntegrationTest {
private static final String LB = "classic-elb-1";
private static String subnetA() { return Ec2Service.defaultSubnetId("us-east-1", "a"); }
private static String subnetA() { return Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"); }
@Test
@Order(1)
@@ -440,7 +440,7 @@ class ElbClassicIntegrationTest {
.formParam("Action", "AttachLoadBalancerToSubnets")
.formParam("Version", V1)
.formParam("LoadBalancerName", LB)
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -448,13 +448,13 @@ class ElbClassicIntegrationTest {
.statusCode(200)
.body("AttachLoadBalancerToSubnetsResponse.AttachLoadBalancerToSubnetsResult"
+ ".Subnets.member", hasItems(subnetA(),
Ec2Service.defaultSubnetId("us-east-1", "b")));
Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
given()
.formParam("Action", "DetachLoadBalancerFromSubnets")
.formParam("Version", V1)
.formParam("LoadBalancerName", LB)
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -520,8 +520,8 @@ class ElbClassicIntegrationTest {
.formParam("Version", V2)
.formParam("Name", "v2-still-works")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -594,7 +594,7 @@ class ElbClassicIntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Version", V1)
.formParam("LoadBalancerName", loadBalancerName)
.formParam("Subnets.member.1", subnetA())
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", SOURCE_GROUP_ACCOUNT))
.formParam("SecurityGroups.member.1", groupId)
.formParam("Listeners.member.1.Protocol", "TCP")
.formParam("Listeners.member.1.LoadBalancerPort", "443")
@@ -80,7 +80,7 @@ class ElbClassicServerCertificateIntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Version", CLASSIC_VERSION)
.formParam("LoadBalancerName", lbName)
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Listeners.member.1.Protocol", "HTTPS")
.formParam("Listeners.member.1.LoadBalancerPort", "443")
.formParam("Listeners.member.1.InstanceProtocol", "HTTP")
@@ -112,7 +112,7 @@ class ElbClassicServerCertificateIntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Version", CLASSIC_VERSION)
.formParam("LoadBalancerName", lb)
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Listeners.member.1.Protocol", "HTTP")
.formParam("Listeners.member.1.LoadBalancerPort", "80")
.formParam("Listeners.member.1.InstancePort", "8080")
@@ -168,7 +168,7 @@ class ElbClassicServerCertificateIntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Version", CLASSIC_VERSION)
.formParam("LoadBalancerName", "elb-cert-http-" + suffix())
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Listeners.member.1.Protocol", "HTTP")
.formParam("Listeners.member.1.LoadBalancerPort", "80")
.formParam("Listeners.member.1.InstanceProtocol", "HTTP")
@@ -61,8 +61,8 @@ class ElbV2AuthenticateActionIntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "auth-action-lb")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))))
.getString("CreateLoadBalancerResponse.CreateLoadBalancerResult"
+ ".LoadBalancers.member.LoadBalancerArn");
@@ -71,7 +71,7 @@ class ElbV2AuthenticateActionIntegrationTest {
.formParam("Name", "auth-action-tg")
.formParam("Protocol", "HTTP")
.formParam("Port", "80")
.formParam("VpcId", Ec2Service.defaultVpcId("us-east-1"))))
.formParam("VpcId", Ec2Service.defaultVpcId("us-east-1", "000000000000"))))
.getString("CreateTargetGroupResponse.CreateTargetGroupResult"
+ ".TargetGroups.member.TargetGroupArn");
}
@@ -88,8 +88,8 @@ class ElbV2CertificateDeleteRaceTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", name)
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.when().post("/").then().statusCode(200)
.extract().path("CreateLoadBalancerResponse.CreateLoadBalancerResult"
+ ".LoadBalancers.member.LoadBalancerArn");
@@ -119,13 +119,13 @@ class ElbV2ForwardConfigIntegrationTest {
void gatewayShortFormForwardOmitsWeightAndStickiness() {
String suffix = UUID.randomUUID().toString().substring(0, 8);
String gatewayArn = elb.createLoadBalancer(request -> request.name("forward-gwy-" + suffix)
.type("gateway").subnets(Ec2Service.defaultSubnetId("us-east-1", "a")))
.type("gateway").subnets(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.loadBalancers().getFirst().loadBalancerArn();
String gatewayGroupArn = null;
try {
gatewayGroupArn = elb.createTargetGroup(request -> request.name("forward-gwy-" + suffix)
.protocol("GENEVE").port(6081).targetType("ip")
.vpcId(Ec2Service.defaultVpcId("us-east-1")))
.vpcId(Ec2Service.defaultVpcId("us-east-1", "000000000000")))
.targetGroups().getFirst().targetGroupArn();
String groupArn = gatewayGroupArn;
Listener listener = elb.createListener(request -> request.loadBalancerArn(gatewayArn)
@@ -1239,8 +1239,8 @@ class ElbV2HttpsDataPlaneIntegrationTest {
Response created = given().header("Authorization", accountAuthorization(owner, "elasticloadbalancing"))
.formParam("Action", "CreateLoadBalancer").formParam("Name", "https-scoped-iam")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId(REGION, "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId(REGION, "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId(REGION, "a", owner))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId(REGION, "b", owner))
.when().post("/").then().statusCode(200).extract().response();
loadBalancer = new LoadBalancerRef(
created.xmlPath().getString("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.LoadBalancerArn"),
@@ -228,7 +228,7 @@ class ElbV2InitialHealthIntegrationTest {
.formParam("Name", name)
.formParam("Protocol", "HTTP")
.formParam("Port", port)
.formParam("VpcId", Ec2Service.defaultVpcId("us-east-1"))
.formParam("VpcId", Ec2Service.defaultVpcId("us-east-1", "000000000000"))
.formParam("TargetType", "ip")
.formParam("HealthCheckPath", "/health")
.formParam("HealthCheckIntervalSeconds", 300)
@@ -79,7 +79,7 @@ class ElbV2IntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "gateway-listener-port")
.formParam("Type", "gateway")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.when().post("/").then().statusCode(200)
.extract().path("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.LoadBalancerArn");
try {
@@ -130,8 +130,8 @@ class ElbV2IntegrationTest {
.formParam("Type", "application")
.formParam("Scheme", "internet-facing")
.formParam("IpAddressType", "ipv4")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -147,7 +147,7 @@ class ElbV2IntegrationTest {
.body("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.State.Code",
equalTo("provisioning"))
.body("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.AvailabilityZones.member.SubnetId",
hasItems(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")))
hasItems(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")))
.body("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.DNSName",
containsString(".elb.localhost.floci.io"))
.extract()
@@ -170,7 +170,7 @@ class ElbV2IntegrationTest {
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.State.Code",
equalTo("active"))
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member.SubnetId",
hasItems(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
hasItems(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
}
@Test
@@ -194,8 +194,8 @@ class ElbV2IntegrationTest {
given()
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "my-test-lb")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -280,8 +280,8 @@ class ElbV2IntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "lb-with-subnets")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -291,11 +291,11 @@ class ElbV2IntegrationTest {
.body("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.AvailabilityZones.member.size()",
equalTo(2))
.body("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.AvailabilityZones.member[0].SubnetId",
equalTo(Ec2Service.defaultSubnetId("us-east-1", "a")))
equalTo(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.body("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.AvailabilityZones.member[0].ZoneName",
equalTo("us-east-1a"))
.body("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.AvailabilityZones.member[1].SubnetId",
equalTo(Ec2Service.defaultSubnetId("us-east-1", "b")))
equalTo(Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")))
.body("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.AvailabilityZones.member[1].ZoneName",
equalTo("us-east-1b"))
.extract()
@@ -312,11 +312,11 @@ class ElbV2IntegrationTest {
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member.size()",
equalTo(2))
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member[0].SubnetId",
equalTo(Ec2Service.defaultSubnetId("us-east-1", "a")))
equalTo(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member[0].ZoneName",
equalTo("us-east-1a"))
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member[1].SubnetId",
equalTo(Ec2Service.defaultSubnetId("us-east-1", "b")))
equalTo(Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")))
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member[1].ZoneName",
equalTo("us-east-1b"));
}
@@ -327,8 +327,8 @@ class ElbV2IntegrationTest {
given()
.formParam("Action", "SetSubnets")
.formParam("LoadBalancerArn", lbArn)
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "c"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "c", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -348,7 +348,7 @@ class ElbV2IntegrationTest {
.then()
.statusCode(200)
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member.SubnetId",
hasItems(Ec2Service.defaultSubnetId("us-east-1", "b"), Ec2Service.defaultSubnetId("us-east-1", "c")));
hasItems(Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "c", "000000000000")));
}
@Test
@@ -393,27 +393,27 @@ class ElbV2IntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "nlb-with-subnet-mappings")
.formParam("Type", "network")
.formParam("SubnetMappings.member.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("SubnetMappings.member.2.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("SubnetMappings.member.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("SubnetMappings.member.2.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
.then()
.statusCode(200)
.body("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.VpcId",
equalTo(Ec2Service.defaultVpcId("us-east-1")))
equalTo(Ec2Service.defaultVpcId("us-east-1", "000000000000")))
.body("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.AvailabilityZones.member.size()",
equalTo(2))
.body("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.AvailabilityZones.member.SubnetId",
hasItems(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")))
hasItems(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")))
.extract()
.path("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.LoadBalancerArn");
given()
.formParam("Action", "SetSubnets")
.formParam("LoadBalancerArn", subnetMappedArn)
.formParam("SubnetMappings.member.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("SubnetMappings.member.2.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "c"))
.formParam("SubnetMappings.member.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.formParam("SubnetMappings.member.2.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "c", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -431,7 +431,7 @@ class ElbV2IntegrationTest {
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member.size()",
equalTo(2))
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member.SubnetId",
hasItems(Ec2Service.defaultSubnetId("us-east-1", "b"), Ec2Service.defaultSubnetId("us-east-1", "c")));
hasItems(Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "c", "000000000000")));
}
@Test
@@ -440,8 +440,8 @@ class ElbV2IntegrationTest {
given()
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "both-subnet-forms")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("SubnetMappings.member.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("SubnetMappings.member.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -502,7 +502,7 @@ class ElbV2IntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "mixed-vpc-lb")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", otherSubnetId)
.header("Authorization", AUTH)
.when()
@@ -543,8 +543,8 @@ class ElbV2IntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "set-subnets-test-lb")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -556,7 +556,7 @@ class ElbV2IntegrationTest {
given()
.formParam("Action", "SetSubnets")
.formParam("LoadBalancerArn", subnetLbArn)
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", otherSubnetId)
.header("Authorization", AUTH)
.when()
@@ -580,7 +580,7 @@ class ElbV2IntegrationTest {
})
@Order(12)
void createLoadBalancerWithOneSubnetIsAValidationError(String name, String type, String parameter, String zone) {
String subnet = zone == null ? "subnet-does-not-exist" : Ec2Service.defaultSubnetId("us-east-1", zone);
String subnet = zone == null ? "subnet-does-not-exist" : Ec2Service.defaultSubnetId("us-east-1", zone, "000000000000");
RequestSpecification request = given()
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", name)
@@ -618,14 +618,14 @@ class ElbV2IntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "single-subnet-" + type)
.formParam("Type", type)
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
.then()
.statusCode(200)
.body("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.AvailabilityZones.member.SubnetId",
equalTo(Ec2Service.defaultSubnetId("us-east-1", "a")))
equalTo(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.extract()
.path("CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member.LoadBalancerArn");
@@ -644,7 +644,7 @@ class ElbV2IntegrationTest {
void createLoadBalancerWithSubnetsInSameAvailabilityZoneThrowsInvalidConfigurationRequest() {
String secondSubnetId = given()
.formParam("Action", "CreateSubnet")
.formParam("VpcId", Ec2Service.defaultVpcId("us-east-1"))
.formParam("VpcId", Ec2Service.defaultVpcId("us-east-1", "000000000000"))
.formParam("CidrBlock", "172.31.64.0/24")
.formParam("AvailabilityZone", "us-east-1a")
.header("Authorization", EC2_AUTH)
@@ -659,7 +659,7 @@ class ElbV2IntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "duplicate-az-lb")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", secondSubnetId)
.header("Authorization", AUTH)
.when()
@@ -674,7 +674,7 @@ class ElbV2IntegrationTest {
void setSubnetsWithSubnetsInSameAvailabilityZoneThrowsInvalidConfigurationRequest() {
String secondSubnetId = given()
.formParam("Action", "CreateSubnet")
.formParam("VpcId", Ec2Service.defaultVpcId("us-east-1"))
.formParam("VpcId", Ec2Service.defaultVpcId("us-east-1", "000000000000"))
.formParam("CidrBlock", "172.31.65.0/24")
.formParam("AvailabilityZone", "us-east-1a")
.header("Authorization", EC2_AUTH)
@@ -689,8 +689,8 @@ class ElbV2IntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "set-duplicate-az-lb")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -702,7 +702,7 @@ class ElbV2IntegrationTest {
given()
.formParam("Action", "SetSubnets")
.formParam("LoadBalancerArn", duplicateAzLbArn)
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", secondSubnetId)
.header("Authorization", AUTH)
.when()
@@ -761,8 +761,8 @@ class ElbV2IntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "other-vpc-subnets-lb")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -793,9 +793,9 @@ class ElbV2IntegrationTest {
.then()
.statusCode(200)
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.VpcId",
equalTo(Ec2Service.defaultVpcId("us-east-1")))
equalTo(Ec2Service.defaultVpcId("us-east-1", "000000000000")))
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member.SubnetId",
contains(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
contains(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
}
@Test
@@ -805,7 +805,7 @@ class ElbV2IntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "missing-subnet-lb")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", "subnet-does-not-exist")
.header("Authorization", AUTH)
.when()
@@ -1475,8 +1475,8 @@ class ElbV2IntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "lb-set-subnets")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -1489,7 +1489,7 @@ class ElbV2IntegrationTest {
given()
.formParam("Action", "SetSubnets")
.formParam("LoadBalancerArn", setSubnetsLbArn)
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", "subnet-does-not-exist")
.header("Authorization", AUTH)
.when()
@@ -1514,9 +1514,9 @@ class ElbV2IntegrationTest {
@Order(68)
void setSubnetsOntoOneSubnetIsAValidationErrorForAnApplicationLoadBalancer(String name, String parameter,
String zone) {
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnetB = Ec2Service.defaultSubnetId("us-east-1", "b");
String subnet = zone == null ? "subnet-does-not-exist" : Ec2Service.defaultSubnetId("us-east-1", zone);
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
String subnetB = Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000");
String subnet = zone == null ? "subnet-does-not-exist" : Ec2Service.defaultSubnetId("us-east-1", zone, "000000000000");
String arn = given()
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", name)
@@ -1555,7 +1555,7 @@ class ElbV2IntegrationTest {
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member.SubnetId",
contains(subnetA, subnetB))
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.VpcId",
equalTo(Ec2Service.defaultVpcId("us-east-1")));
equalTo(Ec2Service.defaultVpcId("us-east-1", "000000000000")));
given()
.formParam("Action", "DeleteLoadBalancer")
@@ -1576,7 +1576,7 @@ class ElbV2IntegrationTest {
@CsvSource({"network,true", "gateway,false"})
@Order(69)
void setSubnetsOntoOneSubnetIsAllowedForNetworkAndGatewayLoadBalancers(String type, boolean onTwoSubnets) {
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
RequestSpecification create = given()
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "set-one-subnet-" + type)
@@ -1584,7 +1584,7 @@ class ElbV2IntegrationTest {
.formParam("Subnets.member.1", subnetA)
.header("Authorization", AUTH);
if (onTwoSubnets) {
create.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"));
create.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"));
}
String arn = create
.when()
@@ -1674,8 +1674,8 @@ class ElbV2IntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "set-both-subnet-forms")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -1687,8 +1687,8 @@ class ElbV2IntegrationTest {
given()
.formParam("Action", "SetSubnets")
.formParam("LoadBalancerArn", bothFormsLbArn)
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("SubnetMappings.member.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "c"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.formParam("SubnetMappings.member.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "c", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -1707,7 +1707,7 @@ class ElbV2IntegrationTest {
.then()
.statusCode(200)
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member.SubnetId",
contains(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
contains(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
}
/**
@@ -1727,8 +1727,8 @@ class ElbV2IntegrationTest {
})
@Order(80)
void setSubnetsWithNeitherSubnetsNorSubnetMappingsIsRefused(String type, boolean emptyLists, String message) {
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnetB = Ec2Service.defaultSubnetId("us-east-1", "b");
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
String subnetB = Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000");
String arn = given()
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "set-none-" + type + (emptyLists ? "-empty" : ""))
@@ -1769,7 +1769,7 @@ class ElbV2IntegrationTest {
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.AvailabilityZones.member.SubnetId",
contains(subnetA, subnetB))
.body("DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member.VpcId",
equalTo(Ec2Service.defaultVpcId("us-east-1")));
equalTo(Ec2Service.defaultVpcId("us-east-1", "000000000000")));
given()
.formParam("Action", "DeleteLoadBalancer")
@@ -118,8 +118,8 @@ class ElbV2LambdaTargetDataPlaneIntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "alb-dataplane-lb")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.header("Authorization", AUTH)
.when()
.post("/")
@@ -54,8 +54,8 @@ class ElbV2LambdaTargetIntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "lambda-target-lb")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.formParam("Scheme", "internet-facing")
.header("Authorization", AUTH)
.when()
@@ -106,8 +106,8 @@ class ElbV2ListenerCertificateIntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "elbv2-cert-" + suffix())
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.when().post("/").then().statusCode(200)
.extract().path("CreateLoadBalancerResponse.CreateLoadBalancerResult"
+ ".LoadBalancers.member.LoadBalancerArn");
@@ -88,7 +88,7 @@ class ElbV2ListenerLookupIntegrationTest {
private static String createBalancer(ElasticLoadBalancingV2Client client, String prefix) {
return client.createLoadBalancer(r -> r.name(prefix + "-" + UUID.randomUUID().toString().substring(0, 8))
.type("application").subnets(List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"))))
.type("application").subnets(List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))))
.loadBalancers().get(0).loadBalancerArn();
}
@@ -161,12 +161,12 @@ class ElbV2ListenerProtocolIntegrationTest {
private void createLoadBalancer(String type) {
loadBalancer = elb.createLoadBalancer(request -> request.name(uniqueName("protocol-lb")).type(type)
.subnets(Ec2Service.defaultSubnetId(REGION.id(), "a"),
Ec2Service.defaultSubnetId(REGION.id(), "b")))
.subnets(Ec2Service.defaultSubnetId(REGION.id(), "a", "000000000000"),
Ec2Service.defaultSubnetId(REGION.id(), "b", "000000000000")))
.loadBalancers().getFirst().loadBalancerArn();
targetGroup = elb.createTargetGroup(request -> request.name(uniqueName("protocol-tg"))
.targetType("ip").protocol(type.equals("network") ? "TCP" : "HTTP").port(80)
.vpcId(Ec2Service.defaultVpcId(REGION.id()))).targetGroups().getFirst().targetGroupArn();
.vpcId(Ec2Service.defaultVpcId(REGION.id(), "000000000000"))).targetGroups().getFirst().targetGroupArn();
}
private Listener createListener(String protocol, String sslPolicy, String certificateArn) {
@@ -48,8 +48,8 @@ class ElbV2OptionalResponseFieldsIntegrationTest {
.validationMethod("DNS")).certificateArn();
loadBalancer = elb.createLoadBalancer(request -> request.name(uniqueName("optional-lb"))
.type("application").subnets(
Ec2Service.defaultSubnetId(REGION.id(), "a"),
Ec2Service.defaultSubnetId(REGION.id(), "b")))
Ec2Service.defaultSubnetId(REGION.id(), "a", "000000000000"),
Ec2Service.defaultSubnetId(REGION.id(), "b", "000000000000")))
.loadBalancers().getFirst().loadBalancerArn();
targetGroup = elb.createTargetGroup(request -> request.name(uniqueName("optional-tg"))
.targetType("lambda")).targetGroups().getFirst().targetGroupArn();
@@ -230,7 +230,7 @@ class ElbV2OptionalResponseFieldsIntegrationTest {
private String createTargetGroup(String prefix, String protocol, String healthCheckProtocol) {
String arn = elb.createTargetGroup(request -> request.name(uniqueName(prefix))
.protocol(protocol).port(2022).targetType("ip")
.vpcId(Ec2Service.defaultVpcId(REGION.id()))
.vpcId(Ec2Service.defaultVpcId(REGION.id(), "000000000000"))
.healthCheckProtocol(healthCheckProtocol))
.targetGroups().getFirst().targetGroupArn();
createdTargetGroups.add(arn);
@@ -25,20 +25,20 @@ class ElbV2RegionalZoneIntegrationTest {
String name = "regional-" + UUID.randomUUID().toString().substring(0, 12);
ElasticLoadBalancingV2Exception rejected = assertThrows(ElasticLoadBalancingV2Exception.class,
() -> virginia.createLoadBalancer(r -> r.name(name).scheme("internal")
.type("application").subnets(Ec2Service.defaultSubnetId("us-east-1", "a"))));
.type("application").subnets(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))));
assertEquals("ValidationError", rejected.awsErrorDetails().errorCode());
ElasticLoadBalancingV2Exception osakaRejected = assertThrows(ElasticLoadBalancingV2Exception.class,
() -> osaka.createLoadBalancer(r -> r.name(name).scheme("internal").type("application")
.subnets(Ec2Service.defaultSubnetId("ap-northeast-3", "a"))));
.subnets(Ec2Service.defaultSubnetId("ap-northeast-3", "a", "000000000000"))));
assertEquals("ValidationError", osakaRejected.awsErrorDetails().errorCode());
String arn = osaka.createLoadBalancer(r -> r.name(name).scheme("internal").type("application")
.subnets(Ec2Service.defaultSubnetId("ap-northeast-3", "a"),
Ec2Service.defaultSubnetId("ap-northeast-3", "b")))
.subnets(Ec2Service.defaultSubnetId("ap-northeast-3", "a", "000000000000"),
Ec2Service.defaultSubnetId("ap-northeast-3", "b", "000000000000")))
.loadBalancers().getFirst().loadBalancerArn();
try {
ElasticLoadBalancingV2Exception updateRejected = assertThrows(
ElasticLoadBalancingV2Exception.class, () -> osaka.setSubnets(r -> r.loadBalancerArn(arn)
.subnets(Ec2Service.defaultSubnetId("ap-northeast-3", "b"))));
.subnets(Ec2Service.defaultSubnetId("ap-northeast-3", "b", "000000000000"))));
assertEquals("ValidationError", updateRejected.awsErrorDetails().errorCode());
assertEquals(2, osaka.describeLoadBalancers(r -> r.loadBalancerArns(arn))
.loadBalancers().getFirst().availabilityZones().size());
@@ -27,7 +27,7 @@ class ElbV2RuleLookupIntegrationTest {
ElasticLoadBalancingV2Client.builder(), "000000000000", Region.US_EAST_1)) {
String balancer = client.createLoadBalancer(r -> r
.name("sdk-rule-" + UUID.randomUUID().toString().substring(0, 8))
.type("application").subnets(List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"))))
.type("application").subnets(List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))))
.loadBalancers().get(0).loadBalancerArn();
try {
String listener = client.createListener(r -> r.loadBalancerArn(balancer).port(8080).protocol("HTTP")
@@ -41,8 +41,8 @@ class ElbV2SamePortHostDispatchIntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "same-port-first")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.formParam("Scheme", "internet-facing")
.header("Authorization", AUTH)
.when()
@@ -79,8 +79,8 @@ class ElbV2SamePortHostDispatchIntegrationTest {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "same-port-second")
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))
.formParam("Scheme", "internet-facing")
.header("Authorization", AUTH)
.when()
@@ -108,11 +108,12 @@ class ElbV2SubnetDependencyIntegrationTest {
@Test
void referencesInAnotherAccountDoNotPinTheSameDefaultSubnetId() {
String otherAccount = TestAccounts.randomId();
String first = Ec2Service.defaultSubnetId(REGION, "a");
String second = Ec2Service.defaultSubnetId(REGION, "b");
String first = Ec2Service.defaultSubnetId(REGION, "a", ACCOUNT);
String second = Ec2Service.defaultSubnetId(REGION, "b", ACCOUNT);
String arn = loadBalancer("application", first, second);
try {
request("ec2", otherAccount, REGION, "DeleteSubnet", "SubnetId", first).statusCode(200);
request("ec2", otherAccount, REGION, "DeleteSubnet", "SubnetId",
Ec2Service.defaultSubnetId(REGION, "a", otherAccount)).statusCode(200);
ec2("DeleteSubnet", "SubnetId", first).statusCode(400)
.body("Response.Errors.Error.Code", equalTo("DependencyViolation"));
} finally {
@@ -120,13 +120,13 @@ class ElbV2TcpDataPlaneIntegrationTest {
loadBalancerArn = client.createLoadBalancer(request -> request
.name("tcp-regression-nlb")
.type(LoadBalancerTypeEnum.NETWORK)
.subnets(Ec2Service.defaultSubnetId("us-east-1", "a")))
.subnets(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.loadBalancers().getFirst().loadBalancerArn();
targetGroupArn = client.createTargetGroup(request -> request
.name("tcp-regression-tg")
.protocol(ProtocolEnum.TCP)
.port(backend.actualPort())
.vpcId(Ec2Service.defaultVpcId("us-east-1"))
.vpcId(Ec2Service.defaultVpcId("us-east-1", "000000000000"))
.targetType(TargetTypeEnum.IP)
.healthCheckProtocol(ProtocolEnum.HTTP)
.healthCheckPort(Integer.toString(healthBackend.actualPort()))
@@ -338,8 +338,8 @@ class ElbV2TcpDataPlaneIntegrationTest {
void secondListenerOnTcpPortRegistersWithoutTakingThePort(ProtocolEnum protocol) throws Exception {
String otherLbArn = client.createLoadBalancer(request -> request.name("tcp-regression-other")
.type(protocol == ProtocolEnum.TCP ? LoadBalancerTypeEnum.NETWORK : LoadBalancerTypeEnum.APPLICATION)
.subnets(Ec2Service.defaultSubnetId("us-east-1", "a"),
Ec2Service.defaultSubnetId("us-east-1", "b")))
.subnets(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"),
Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")))
.loadBalancers().getFirst().loadBalancerArn();
try {
Action action = protocol == ProtocolEnum.TCP
@@ -366,8 +366,8 @@ class ElbV2TcpDataPlaneIntegrationTest {
LoadBalancer other = client.createLoadBalancer(
request -> request.name("tcp-regression-parked")
.type(LoadBalancerTypeEnum.APPLICATION)
.subnets(Ec2Service.defaultSubnetId("us-east-1", "a"),
Ec2Service.defaultSubnetId("us-east-1", "b")))
.subnets(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"),
Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")))
.loadBalancers().getFirst();
try {
client.createListener(request -> request.loadBalancerArn(other.loadBalancerArn())
@@ -402,8 +402,8 @@ class ElbV2TcpDataPlaneIntegrationTest {
void listenerStartsAfterExternalPortOwnerReleasesIt(ProtocolEnum protocol) throws Exception {
LoadBalancer other = client.createLoadBalancer(request -> request.name("tcp-regression-occupied")
.type(protocol == ProtocolEnum.TCP ? LoadBalancerTypeEnum.NETWORK : LoadBalancerTypeEnum.APPLICATION)
.subnets(Ec2Service.defaultSubnetId("us-east-1", "a"),
Ec2Service.defaultSubnetId("us-east-1", "b")))
.subnets(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"),
Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")))
.loadBalancers().getFirst();
try (ServerSocket occupied = new ServerSocket(0)) {
int port = occupied.getLocalPort();
@@ -482,7 +482,7 @@ class ElbV2TcpDataPlaneIntegrationTest {
@Test
void updatingForwardActionOnlyChangesNewTcpConnections() throws Exception {
String emptyTgArn = client.createTargetGroup(request -> request.name("tcp-regression-empty")
.protocol(ProtocolEnum.TCP).port(12345).vpcId(Ec2Service.defaultVpcId("us-east-1"))
.protocol(ProtocolEnum.TCP).port(12345).vpcId(Ec2Service.defaultVpcId("us-east-1", "000000000000"))
.targetType(TargetTypeEnum.IP)).targetGroups().getFirst().targetGroupArn();
try {
try (Socket established = connect(listenerPort)) {
@@ -78,7 +78,7 @@ class EventBridgeEcsRunTaskIntegrationTest {
}
}]
}
""".formatted(ruleName, clusterArn, taskDefinitionArn, suffix, Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"), Ec2Service.defaultSecurityGroupId("us-east-1")))
""".formatted(ruleName, clusterArn, taskDefinitionArn, suffix, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"), Ec2Service.defaultSecurityGroupId("us-east-1", "000000000000")))
.when()
.post("/")
.then()
@@ -101,9 +101,9 @@ class EventBridgeEcsRunTaskIntegrationTest {
.body("Targets[0].EcsParameters.LaunchType", equalTo("FARGATE"))
.body("Targets[0].EcsParameters.Group", equalTo("eb-ecs-group-" + suffix))
.body("Targets[0].EcsParameters.NetworkConfiguration.awsvpcConfiguration.Subnets",
hasItem(Ec2Service.defaultSubnetId("us-east-1", "a")))
hasItem(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")))
.body("Targets[0].EcsParameters.NetworkConfiguration.awsvpcConfiguration.SecurityGroups",
hasItem(Ec2Service.defaultSecurityGroupId("us-east-1")))
hasItem(Ec2Service.defaultSecurityGroupId("us-east-1", "000000000000")))
.body("Targets[0].EcsParameters.NetworkConfiguration.awsvpcConfiguration.AssignPublicIp",
equalTo("ENABLED"));
@@ -1104,7 +1104,7 @@ class IamPassRoleEnforcementIntegrationTest {
return """
{"cluster":"%s","taskDefinition":"%s","launchType":"FARGATE","count":1,
"networkConfiguration":{"awsvpcConfiguration":{"subnets":["%s"]}}%s}"""
.formatted(cluster, family, Ec2Service.defaultSubnetId("us-east-1", "a"),
.formatted(cluster, family, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"),
taskRoleOverride == null ? ""
: ",\"overrides\":{\"taskRoleArn\":\"" + taskRoleOverride + "\"}");
}
@@ -1113,7 +1113,7 @@ class IamPassRoleEnforcementIntegrationTest {
return """
{"cluster":"%s","serviceName":"%s","taskDefinition":"%s","desiredCount":0,"launchType":"FARGATE",
"networkConfiguration":{"awsvpcConfiguration":{"subnets":["%s"]}}}"""
.formatted(cluster, name, family, Ec2Service.defaultSubnetId("us-east-1", "a"));
.formatted(cluster, name, family, Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"));
}
private static RequestSpecification createStack(User user, String stack) {
@@ -40,8 +40,8 @@ class OpenSearchVpcEndpointIntegrationTest {
private static final String VPC_DOMAIN = "vpce-domain";
private static final String PUBLIC_DOMAIN = "vpce-public";
// The seeded default subnets, so EC2 can name their VPC and zones.
private static final String SUBNET_A = Ec2Service.defaultSubnetId("us-east-1", "a");
private static final String SUBNET_B = Ec2Service.defaultSubnetId("us-east-1", "b");
private static final String SUBNET_A = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
private static final String SUBNET_B = Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000");
@Inject
Ec2Service ec2Service;
@@ -42,8 +42,8 @@ class RdsProxyEndpointIntegrationTest {
}
private static RequestSpecification withSubnets(RequestSpecification request) {
return request.formParam("VpcSubnetIds.member.1", Ec2Service.defaultSubnetId(REGION, "a"))
.formParam("VpcSubnetIds.member.2", Ec2Service.defaultSubnetId(REGION, "b"));
return request.formParam("VpcSubnetIds.member.1", Ec2Service.defaultSubnetId(REGION, "a", "000000000000"))
.formParam("VpcSubnetIds.member.2", Ec2Service.defaultSubnetId(REGION, "b", "000000000000"));
}
private static RequestSpecification describe() {
@@ -144,7 +144,7 @@ class RdsProxyEndpointIntegrationTest {
.body(containsString("<Code>InvalidParameterValue</Code>"));
query("CreateDBProxyEndpoint")
.formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "lonely")
.formParam("VpcSubnetIds.member.1", Ec2Service.defaultSubnetId(REGION, "a"))
.formParam("VpcSubnetIds.member.1", Ec2Service.defaultSubnetId(REGION, "a", "000000000000"))
.when().post("/").then().statusCode(400)
.body(containsString("<Code>InvalidSubnet</Code>"));
withSubnets(query("CreateDBProxyEndpoint")).formParam("DBProxyEndpointName", "orphan")
@@ -3587,8 +3587,8 @@ class RdsQueryHandlerTest {
group.setDbSubnetGroupArn("arn:aws:rds:us-east-1:123456789012:subgrp:default");
group.setVpcId("vpc-default");
group.setSubnetGroupStatus("Complete");
group.setSubnetIds(List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
group.setSubnetAvailabilityZones(Map.of(Ec2Service.defaultSubnetId("us-east-1", "a"), "us-east-1a", Ec2Service.defaultSubnetId("us-east-1", "b"), "us-east-1b"));
group.setSubnetIds(List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
group.setSubnetAvailabilityZones(Map.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), "us-east-1a", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"), "us-east-1b"));
return group;
}
@@ -273,8 +273,8 @@ class RdsResourceIamIntegrationTest {
for (String proxyName : List.of(name, other)) {
root.createDBProxy(r -> r.dbProxyName(proxyName).engineFamily("POSTGRESQL")
.roleArn(prefix + "iam::" + ACCOUNT + ":role/proxy")
.vpcSubnetIds(Ec2Service.defaultSubnetId(regionName, "a"),
Ec2Service.defaultSubnetId(regionName, "b"))
.vpcSubnetIds(Ec2Service.defaultSubnetId(regionName, "a", "000000000000"),
Ec2Service.defaultSubnetId(regionName, "b", "000000000000"))
.auth(a -> a.authScheme("SECRETS")
.secretArn(prefix + "secretsmanager:" + regionName + ":" + ACCOUNT + ":secret:db-AbCdEf"))
.tags(tag("Owner", "team-a")));
@@ -284,8 +284,8 @@ class RdsResourceIamIntegrationTest {
String targetArn = root.describeDBProxyTargetGroups(r -> r.dbProxyName(name))
.targetGroups().getFirst().targetGroupArn();
String endpointArn = root.createDBProxyEndpoint(r -> r.dbProxyName(name).dbProxyEndpointName(name)
.vpcSubnetIds(Ec2Service.defaultSubnetId(regionName, "a"),
Ec2Service.defaultSubnetId(regionName, "b"))).dbProxyEndpoint().dbProxyEndpointArn();
.vpcSubnetIds(Ec2Service.defaultSubnetId(regionName, "a", "000000000000"),
Ec2Service.defaultSubnetId(regionName, "b", "000000000000"))).dbProxyEndpoint().dbProxyEndpointArn();
policy(user, """
[{"Effect":"Allow","Action":"rds:ModifyDBProxy","Resource":"%s",
"Condition":{"StringEquals":{"aws:ResourceTag/Owner":"team-a"}}},
@@ -398,7 +398,7 @@ class RdsResourceIamIntegrationTest {
.dbClusterParameterGroup().dbClusterParameterGroupArn();
case "subgrp" -> client.createDBSubnetGroup(r -> r.dbSubnetGroupName(name)
.dbSubnetGroupDescription("IAM regression").tags(tag)
.subnetIds(Ec2Service.defaultSubnetId(region, "a"), Ec2Service.defaultSubnetId(region, "b")))
.subnetIds(Ec2Service.defaultSubnetId(region, "a", "000000000000"), Ec2Service.defaultSubnetId(region, "b", "000000000000")))
.dbSubnetGroup().dbSubnetGroupArn();
case "db" -> client.createDBInstance(r -> r.dbInstanceIdentifier(name).engine("postgres")
.dbInstanceClass("db.t3.micro").allocatedStorage(20).masterUsername("admin")
@@ -417,7 +417,7 @@ class RdsResourceIamIntegrationTest {
.parameters(parameter -> parameter.parameterName("log_min_duration_statement")
.parameterValue("1000").applyMethod("immediate")));
case "subgrp" -> client.modifyDBSubnetGroup(r -> r.dbSubnetGroupName(name).dbSubnetGroupDescription("updated")
.subnetIds(Ec2Service.defaultSubnetId(region, "a"), Ec2Service.defaultSubnetId(region, "b")));
.subnetIds(Ec2Service.defaultSubnetId(region, "a", "000000000000"), Ec2Service.defaultSubnetId(region, "b", "000000000000")));
case "db" -> client.modifyDBInstance(r -> r.dbInstanceIdentifier(name).backupRetentionPeriod(2));
case "cluster" -> client.modifyDBCluster(r -> r.dbClusterIdentifier(name).backupRetentionPeriod(2));
default -> throw new IllegalArgumentException(type);
@@ -139,7 +139,7 @@ class RdsServiceTest {
private static final String PROXY_ROLE_ARN = "arn:aws:iam::123456789012:role/proxy";
private static final List<String> PROXY_SUBNET_IDS =
List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"));
List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"));
private static final List<DbProxyAuth> PROXY_AUTH = List.of(new DbProxyAuth(
"SECRETS", "arn:aws:secretsmanager:us-east-1:123456789012:secret:db-AbCdEf",
"DISABLED", null, null));
@@ -219,7 +219,7 @@ class RdsServiceTest {
when(containerManager.tryStart(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(new RdsContainerHandle("cont-id", "id", "localhost", 5432));
when(ec2Service.resolveDefaultVpcId(any()))
.thenAnswer(invocation -> Ec2Service.defaultVpcId(invocation.getArgument(0)));
.thenAnswer(invocation -> Ec2Service.defaultVpcId(invocation.getArgument(0), "000000000000"));
when(ec2Service.describeSubnets(any(), anyList(), any()))
.thenAnswer(invocation -> {
@SuppressWarnings("unchecked")
@@ -3346,7 +3346,7 @@ class RdsServiceTest {
@Test
void createDbInstanceOmittedPubliclyAccessibleDefaultsFalseForNamedNonDefaultSubnetGroup() {
rdsService.createDbSubnetGroup("custom-subnets", "test", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
rdsService.createDbSubnetGroup("custom-subnets", "test", List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
DbInstance instance = rdsService.createDbInstance("custom-subnet-db", "postgres", "13",
"admin", "password", "dbname", "db.t3.micro",
@@ -5266,10 +5266,10 @@ class RdsServiceTest {
@Test
void dbSubnetGroupRoundTrip() {
DbSubnetGroup group = rdsService.createDbSubnetGroup(
"sample-db-subnets", "test", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
"sample-db-subnets", "test", List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
assertEquals("sample-db-subnets", group.getDbSubnetGroupName());
assertEquals(List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")), group.getSubnetIds());
assertEquals(List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")), group.getSubnetIds());
assertEquals(1, rdsService.listDbSubnetGroups("sample-db-subnets").size());
rdsService.deleteDbSubnetGroup("sample-db-subnets");
@@ -5297,7 +5297,7 @@ class RdsServiceTest {
@Test
void dbSubnetGroupTagsRoundTripAndMutateByArn() {
rdsService.createDbSubnetGroup(
"sample-db-subnets", "test", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
"sample-db-subnets", "test", List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
String arn = "arn:aws:rds:us-east-1:123456789012:subgrp:sample-db-subnets";
// A subnet group with no tags must list cleanly — previously this threw DBInstanceNotFound (404)
@@ -5315,11 +5315,11 @@ class RdsServiceTest {
@Test
void dbSubnetGroupTagsSurviveModify() {
rdsService.createDbSubnetGroup(
"sample-db-subnets", "test", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
"sample-db-subnets", "test", List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
String arn = "arn:aws:rds:us-east-1:123456789012:subgrp:sample-db-subnets";
rdsService.addTagsToResource(arn, Map.of("Name", "sample-db-subnets"));
rdsService.modifyDbSubnetGroup("sample-db-subnets", List.of(Ec2Service.defaultSubnetId("us-east-1", "a")));
rdsService.modifyDbSubnetGroup("sample-db-subnets", List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000")));
assertEquals(Map.of("Name", "sample-db-subnets"),
rdsService.listTagsForResource(arn));
@@ -7014,7 +7014,7 @@ class RdsServiceTest {
new InMemoryStorage<>();
DbSubnetGroup subnetGroup = new DbSubnetGroup(
"legacy-subnets", "legacy", "vpc-default", PROXY_SUBNET_IDS,
Map.of(Ec2Service.defaultSubnetId("us-east-1", "a"), "us-east-1a", Ec2Service.defaultSubnetId("us-east-1", "b"), "us-east-1b"));
Map.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), "us-east-1a", Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"), "us-east-1b"));
subnetGroup.setDbSubnetGroupArn(
"arn:aws:rds:us-east-1:" + accountId + ":subgrp:legacy-subnets");
rawSubnetGroups.put("legacy-subnets", subnetGroup);
@@ -7114,10 +7114,10 @@ class RdsServiceTest {
@Test
void createDbSubnetGroupRejectsDuplicateWithModelCode() {
rdsService.createDbSubnetGroup("my-subnet-group", "desc", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
rdsService.createDbSubnetGroup("my-subnet-group", "desc", List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
AwsException exception = assertThrows(AwsException.class, () ->
rdsService.createDbSubnetGroup("my-subnet-group", "desc", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"))));
rdsService.createDbSubnetGroup("my-subnet-group", "desc", List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"))));
assertEquals("DBSubnetGroupAlreadyExists", exception.getErrorCode());
}
@@ -7125,7 +7125,7 @@ class RdsServiceTest {
@Test
void createDbSubnetGroupPopulatesArn() {
DbSubnetGroup group = rdsService.createDbSubnetGroup("my-subnet-group", "desc",
List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
assertEquals("arn:aws:rds:us-east-1:123456789012:subgrp:my-subnet-group", group.getDbSubnetGroupArn());
}
@@ -7191,7 +7191,7 @@ class RdsServiceTest {
@Test
void resolveDbSubnetGroupViewReturnsStoredCustomGroup() {
rdsService.createDbSubnetGroup("my-subnet-group", "desc", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
rdsService.createDbSubnetGroup("my-subnet-group", "desc", List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")));
DbSubnetGroup group = rdsService.resolveDbSubnetGroupView("my-subnet-group");
@@ -11978,8 +11978,8 @@ class RdsServiceTest {
private static List<Subnet> defaultSubnets() {
return List.of(
subnet(Ec2Service.defaultSubnetId("us-east-1", "a"), "vpc-default", "us-east-1a"),
subnet(Ec2Service.defaultSubnetId("us-east-1", "b"), "vpc-default", "us-east-1b"));
subnet(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), "vpc-default", "us-east-1a"),
subnet(Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000"), "vpc-default", "us-east-1b"));
}
private static DbInstance persistedInstance(
@@ -12055,7 +12055,7 @@ class RdsServiceTest {
@Test
void createDbSubnetGroupStoresTheTagsItIsGiven() {
rdsService.createDbSubnetGroup("tagged", "d", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")), "us-east-1",
rdsService.createDbSubnetGroup("tagged", "d", List.of(Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"), Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")), "us-east-1",
Map.of("Name", "tagged", "env", "tst"));
String arn = "arn:aws:rds:us-east-1:123456789012:subgrp:tagged";
@@ -12073,7 +12073,7 @@ class RdsServiceTest {
@Test
void createDbSubnetGroupErrorNamesMissingSubnetIds() {
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a");
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000");
AwsException ex = assertThrows(AwsException.class, () ->
rdsService.createDbSubnetGroup("grp", "desc",
@@ -54,8 +54,8 @@ class RdsTerminalMarkerIntegrationTest {
.dbClusterParameterGroup().dbClusterParameterGroupName();
subnetGroup = client.createDBSubnetGroup(request -> request.dbSubnetGroupName(name)
.dbSubnetGroupDescription("terminal marker test").subnetIds(
Ec2Service.defaultSubnetId("us-east-1", "a"),
Ec2Service.defaultSubnetId("us-east-1", "b")))
Ec2Service.defaultSubnetId("us-east-1", "a", "000000000000"),
Ec2Service.defaultSubnetId("us-east-1", "b", "000000000000")))
.dbSubnetGroup().dbSubnetGroupName();
instance = client.createDBInstance(request -> request.dbInstanceIdentifier(name).engine("postgres")
.dbInstanceClass("db.t3.micro").allocatedStorage(20)
@@ -17,7 +17,7 @@ import static org.hamcrest.Matchers.equalTo;
*/
public final class AlbFixtures {
private static final String DEFAULT_ACCOUNT = "test";
private static final String DEFAULT_ACCOUNT = "000000000000";
private AlbFixtures() {
}
@@ -31,8 +31,8 @@ public final class AlbFixtures {
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", name)
.formParam("Type", "application")
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a", account))
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b", account))
.header("Authorization", auth(account))
.when()
.post("/")