mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ec2): make default network resource IDs region-unique and AWS-format (#7738)
This commit is contained in:
1 parent
651ac1cbe7
commit
1dadaee351
29 files changed
+315
-131
No files matched your search
+10
-8
@@ -350,14 +350,16 @@ Floci seeds the following resources on first use in each region so Terraform, th
|
||||
|
||||
| Resource | ID | Details |
|
||||
|---|---|---|
|
||||
| Default VPC | `vpc-default` | CIDR `172.31.0.0/16` |
|
||||
| Default Subnet (AZ a) | `subnet-default-a` | CIDR `172.31.0.0/20` |
|
||||
| Default Subnet (AZ b) | `subnet-default-b` | CIDR `172.31.16.0/20` |
|
||||
| Default Subnet (AZ c) | `subnet-default-c` | CIDR `172.31.32.0/20` |
|
||||
| Default Security Group | `sg-default` | `groupName=default`, all-traffic egress |
|
||||
| Default Internet Gateway | `igw-default` | Attached to default VPC |
|
||||
| Main Route Table | `rtb-default` | Associated with default VPC |
|
||||
| Default Network ACL | `acl-default` | Allow-all, associated with the default subnets |
|
||||
| Default VPC | `vpc-<17 hex>` | CIDR `172.31.0.0/16`; derived from the region, stable across restarts |
|
||||
| Default Subnet (AZ a) | `subnet-<17 hex>` | CIDR `172.31.0.0/20`; derived from the region and zone |
|
||||
| Default Subnet (AZ b) | `subnet-<17 hex>` | CIDR `172.31.16.0/20`; derived from the region and zone |
|
||||
| Default Subnet (AZ c) | `subnet-<17 hex>` | CIDR `172.31.32.0/20`; derived from the region and zone |
|
||||
| Default Security Group | `sg-<17 hex>` | `groupName=default`, all-traffic egress; derived from the region |
|
||||
| Default Internet Gateway | `igw-<17 hex>` | Attached to default VPC; derived from the region |
|
||||
| Main Route Table | `rtb-<17 hex>` | Associated with default VPC; derived from the region |
|
||||
| Default Network ACL | `acl-<17 hex>` | Allow-all, associated with the default subnets; derived from the region |
|
||||
|
||||
The exact ids are region-derived (a hash of the region, plus the zone or subnet where there is more than one) and differ between regions; discover the real ids through the Describe APIs rather than hard-coding them.
|
||||
|
||||
## Supported Actions
|
||||
|
||||
|
||||
@@ -264,7 +264,7 @@ aws elbv2 create-load-balancer \
|
||||
--name my-alb \
|
||||
--type application \
|
||||
--scheme internet-facing \
|
||||
--subnets subnet-default-us-east-1-a subnet-default-us-east-1-b
|
||||
--subnets subnet-8068005281bb3dc6a subnet-c8ba5d8ce63635cea
|
||||
|
||||
# Create a target group
|
||||
aws elbv2 create-target-group \
|
||||
|
||||
@@ -285,6 +285,7 @@ public class DocDbService {
|
||||
* the family's default parameter group, the VPC's default security group, one day of backups
|
||||
* and windows clear of each other; on modify it keeps the cluster's.
|
||||
*/
|
||||
|
||||
private DocDbClusterSettings resolveClusterSettings(DocDbClusterSettings settings, DocDbCluster current,
|
||||
String engineVersion, String region) {
|
||||
boolean create = current == null;
|
||||
@@ -338,7 +339,7 @@ public class DocDbService {
|
||||
}
|
||||
RdsSecurityGroups.requireInVpc(ec2Service, region, securityGroups, null);
|
||||
} else if (create) {
|
||||
securityGroups = List.of(Ec2Service.defaultSecurityGroupId(region));
|
||||
securityGroups = List.of(resolveDefaultSecurityGroupId(ec2Service, region));
|
||||
}
|
||||
String kmsKeyArn = resolveKmsKeyArn(settings.kmsKeyId(), region);
|
||||
String backup = settings.preferredBackupWindow();
|
||||
@@ -383,6 +384,16 @@ public class DocDbService {
|
||||
backup, maintenance, settings.deletionProtection());
|
||||
}
|
||||
|
||||
/** 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);
|
||||
}
|
||||
|
||||
/** The family of the group a cluster is on; a group deleted since is judged by nothing. */
|
||||
private String currentParameterGroupFamily(String name, String region) {
|
||||
try {
|
||||
@@ -493,7 +504,7 @@ public class DocDbService {
|
||||
changed = true;
|
||||
}
|
||||
if (cluster.getVpcSecurityGroupIds() == null || cluster.getVpcSecurityGroupIds().isEmpty()) {
|
||||
cluster.setVpcSecurityGroupIds(List.of(Ec2Service.defaultSecurityGroupId(region)));
|
||||
cluster.setVpcSecurityGroupIds(List.of(resolveDefaultSecurityGroupId(ec2Service, region)));
|
||||
changed = true;
|
||||
}
|
||||
if (cluster.getPreferredBackupWindow() == null) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.floci.aws.services.ec2;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/** The random parts of the resource ids EC2 mints. */
|
||||
@@ -19,4 +21,16 @@ final class Ec2Ids {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/** Deterministic 17-hex-digit suffix from a seed string, stable across restarts. */
|
||||
static String stableHex(String seed) {
|
||||
String hex = UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8))
|
||||
.toString().replace("-", "");
|
||||
return hex.substring(0, 17);
|
||||
}
|
||||
|
||||
/** Deterministic ENI id from a seed string, stable across restarts. */
|
||||
static String eniIdFromSeed(String seed) {
|
||||
return "eni-" + stableHex(seed);
|
||||
}
|
||||
}
|
||||
@@ -1557,7 +1557,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
defaultVpc.setOwnerId(ownerAccountId);
|
||||
defaultVpc.setRegion(region);
|
||||
defaultVpc.getCidrBlockAssociationSet().add(
|
||||
new VpcCidrBlockAssociation("vpc-cidr-assoc-default", "172.31.0.0/16"));
|
||||
new VpcCidrBlockAssociation("vpc-cidr-assoc-" + Ec2Ids.stableHex("vpc-cidr-assoc::" + region), "172.31.0.0/16"));
|
||||
vpcs.put(key(region, vpcId), defaultVpc);
|
||||
declareVpcNetwork(region, vpcId, "172.31.0.0/16");
|
||||
|
||||
@@ -1588,22 +1588,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
|
||||
createDefaultSecurityGroup(region, vpcId, defaultSecurityGroupId(region));
|
||||
|
||||
// Default NACL, with the default subnets associated to it.
|
||||
String defaultAclId = createDefaultNetworkAcl(region, vpcId, "acl-default");
|
||||
NetworkAcl defaultAcl = networkAcls.get(key(region, defaultAclId)).orElse(null);
|
||||
if (defaultAcl != null) {
|
||||
for (String subnetId : subnetIds) {
|
||||
NetworkAclAssociation assoc = new NetworkAclAssociation();
|
||||
assoc.setNetworkAclAssociationId("aclassoc-" + subnetId);
|
||||
assoc.setNetworkAclId(defaultAclId);
|
||||
assoc.setSubnetId(subnetId);
|
||||
defaultAcl.getAssociations().add(assoc);
|
||||
}
|
||||
networkAcls.put(key(region, defaultAclId), defaultAcl);
|
||||
}
|
||||
|
||||
// Default internet gateway
|
||||
String igwId = "igw-default";
|
||||
String igwId = defaultInternetGatewayId(region);
|
||||
InternetGateway igw = new InternetGateway();
|
||||
igw.setInternetGatewayId(igwId);
|
||||
igw.setOwnerId(ownerAccountId);
|
||||
@@ -1611,12 +1597,30 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
igw.getAttachments().add(new InternetGatewayAttachment(vpcId, "available"));
|
||||
internetGateways.put(key(region, igwId), igw);
|
||||
|
||||
String rtId = createMainRouteTable(region, defaultVpc, "rtb-default", "rtbassoc-default");
|
||||
String rtId = defaultRouteTableId(region);
|
||||
String rtAssocId = defaultRouteTableAssociationId(region);
|
||||
createMainRouteTable(region, defaultVpc, rtId, rtAssocId);
|
||||
|
||||
RouteTable mainRt = routeTables.get(key(region, rtId)).orElse(null);
|
||||
if (mainRt != null) {
|
||||
mainRt.getRoutes().add(new Route("0.0.0.0/0", igwId, "CreateRoute"));
|
||||
}
|
||||
|
||||
// Default NACL - create and associate with default subnets
|
||||
String defaultAclId = defaultNetworkAclId(region);
|
||||
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);
|
||||
NetworkAclAssociation assoc = new NetworkAclAssociation();
|
||||
assoc.setNetworkAclAssociationId(assocId);
|
||||
assoc.setNetworkAclId(defaultAclId);
|
||||
assoc.setSubnetId(subnetId);
|
||||
defaultAcl.getAssociations().add(assoc);
|
||||
}
|
||||
networkAcls.put(key(region, defaultAclId), defaultAcl);
|
||||
}
|
||||
}
|
||||
|
||||
private void createDefaultSecurityGroup(String region, String vpcId, String securityGroupId) {
|
||||
@@ -2196,11 +2200,11 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
// 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-default-" + region;
|
||||
return "vpc-" + Ec2Ids.stableHex("vpc::" + region);
|
||||
}
|
||||
|
||||
public static String defaultSubnetId(String region, String azSuffix) {
|
||||
return "subnet-default-" + region + "-" + azSuffix;
|
||||
return "subnet-" + Ec2Ids.stableHex("subnet::" + region + "::" + azSuffix);
|
||||
}
|
||||
|
||||
public static boolean isModelledAvailabilityZone(String region, String zone) {
|
||||
@@ -2208,18 +2212,76 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
|
||||
public static String defaultSecurityGroupId(String region) {
|
||||
return "sg-default-" + region;
|
||||
return "sg-" + Ec2Ids.stableHex("sg::" + region);
|
||||
}
|
||||
|
||||
// Persisted default VPCs may retain the unscoped id from before ids became region-scoped.
|
||||
// Resolve against storage so callers still find the existing VPC instead of a computed id.
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// 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.
|
||||
public String resolveDefaultVpcId(String region) {
|
||||
String scoped = defaultVpcId(region);
|
||||
if (vpcs.get(key(region, scoped)).isPresent()) {
|
||||
return scoped;
|
||||
}
|
||||
String legacy = "vpc-default";
|
||||
return vpcs.get(key(region, legacy)).isPresent() ? legacy : scoped;
|
||||
// Legacy literals from before ids became region-scoped.
|
||||
for (String legacy : List.of("vpc-default", "vpc-default-" + region)) {
|
||||
if (vpcs.get(key(region, legacy)).isPresent()) {
|
||||
return legacy;
|
||||
}
|
||||
}
|
||||
return scoped;
|
||||
}
|
||||
|
||||
public String resolveDefaultSecurityGroupId(String region) {
|
||||
String scoped = defaultSecurityGroupId(region);
|
||||
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)) {
|
||||
if (securityGroups.get(key(region, legacy)).isPresent()) {
|
||||
return legacy;
|
||||
}
|
||||
}
|
||||
return scoped;
|
||||
}
|
||||
|
||||
// Per-resource mutation locks (#1464): storage get() returns the live stored object, so
|
||||
@@ -4054,10 +4116,12 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
} else if (availabilityZone != null && !availabilityZone.isBlank()) {
|
||||
subnet = resolveSubnetForAvailabilityZone(region, availabilityZone);
|
||||
} else {
|
||||
// Pick first default subnet
|
||||
// Pick the default subnet of the region's first availability zone. Storage order is
|
||||
// not the creation order, so a scan's findFirst is whichever entry the map hashes
|
||||
// first; the choice has to stay us-east-1a whatever the ids are.
|
||||
subnet = subnets.scan(k -> true).stream()
|
||||
.filter(s -> s.getRegion().equals(region) && s.isDefaultForAz())
|
||||
.findFirst()
|
||||
.min(Comparator.comparing(Subnet::getAvailabilityZone))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@@ -7383,7 +7447,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
* <p>Split out so that everything reporting an endpoint's interfaces -- the ids on
|
||||
* the wire, the objects flow-log attribution reads -- comes from one place and
|
||||
* cannot disagree. The alternative, deriving ids independently from the same
|
||||
* {@link #eniIdFromSeed}, looks equivalent and is not: this method skips a subnet
|
||||
* {@link Ec2Ids#eniIdFromSeed}, looks equivalent and is not: this method skips a subnet
|
||||
* whose record has gone, and a second derivation that forgot to would report an
|
||||
* interface the first one denies exists. Congruence by construction beats congruence
|
||||
* by inspection, and the two had in fact already diverged.
|
||||
@@ -7415,7 +7479,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
continue;
|
||||
}
|
||||
NetworkInterface ni = new NetworkInterface();
|
||||
ni.setNetworkInterfaceId(eniIdFromSeed(endpoint.getVpcEndpointId() + "|" + subnetId));
|
||||
ni.setNetworkInterfaceId(Ec2Ids.eniIdFromSeed(endpoint.getVpcEndpointId() + "|" + subnetId));
|
||||
ni.setSubnetId(subnetId);
|
||||
ni.setVpcId(endpoint.getVpcId());
|
||||
ni.setAvailabilityZone(subnet.getAvailabilityZone());
|
||||
@@ -7478,13 +7542,6 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
return result;
|
||||
}
|
||||
|
||||
/** A stable interface id derived from {@code seed}, for interfaces Floci projects rather than stores. */
|
||||
private static String eniIdFromSeed(String seed) {
|
||||
String hex = UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8))
|
||||
.toString().replace("-", "");
|
||||
return "eni-" + hex.substring(0, 17);
|
||||
}
|
||||
|
||||
/**
|
||||
* The network interfaces an interface endpoint owns, by id, in subnet order.
|
||||
*
|
||||
@@ -7496,7 +7553,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
* <p>Mapped over {@link #endpointNetworkInterfacesOf(VpcEndpoint)} rather than derived
|
||||
* separately, so the ids on the wire come BY CONSTRUCTION from the same derivation
|
||||
* flow-log attribution uses, and no endpoint can be described two ways. An earlier
|
||||
* version of this method called {@link #eniIdFromSeed} itself and looked equivalent;
|
||||
* version of this method called {@link Ec2Ids#eniIdFromSeed} itself and looked equivalent;
|
||||
* it was not, because it lacked that method's skip of a subnet whose record has gone,
|
||||
* and the two were measured reporting different sets after a subnet was deleted out
|
||||
* from under a live endpoint.
|
||||
@@ -13359,7 +13416,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
private NatGatewayAddress natGatewayAddress(String region, String natGatewayId, String allocationId,
|
||||
String privateIp) {
|
||||
NatGatewayAddress address = new NatGatewayAddress();
|
||||
address.setNetworkInterfaceId(eniIdFromSeed("nat|" + natGatewayId));
|
||||
address.setNetworkInterfaceId(Ec2Ids.eniIdFromSeed("nat|" + natGatewayId));
|
||||
address.setPrivateIp(privateIp);
|
||||
if (isSet(allocationId)) {
|
||||
address.setAllocationId(allocationId);
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.cloudformation;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
@@ -65,7 +66,7 @@ class CloudFormationEcsDeleteAfterRestoreIntegrationTest {
|
||||
// in-memory RUNNING with no container behind it.
|
||||
ecs("RunTask", "{\"cluster\":\"" + cluster + "\",\"taskDefinition\":\"" + family + "\",\"count\":1,"
|
||||
+ "\"networkConfiguration\":{\"awsvpcConfiguration\":"
|
||||
+ "{\"subnets\":[\"subnet-default-us-east-1-a\"]}}}");
|
||||
+ "{\"subnets\":[\"" + Ec2Service.defaultSubnetId("us-east-1", "a") + "\"]}}}");
|
||||
|
||||
deleteStack(stack);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.dms;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
@@ -29,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 = "subnet-default-us-east-1-a";
|
||||
private static final String SUBNET_B = "subnet-default-us-east-1-b";
|
||||
private static final String SUBNET_A = Ec2Service.defaultSubnetId("us-east-1", "a");
|
||||
private static final String SUBNET_B = Ec2Service.defaultSubnetId("us-east-1", "b");
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
@@ -59,7 +60,7 @@ class DmsIntegrationTest {
|
||||
.body("ReplicationSubnetGroups", hasSize(1))
|
||||
.body("ReplicationSubnetGroups[0].ReplicationSubnetGroupDescription",
|
||||
equalTo("terraform managed"))
|
||||
.body("ReplicationSubnetGroups[0].VpcId", equalTo("vpc-default-us-east-1"))
|
||||
.body("ReplicationSubnetGroups[0].VpcId", equalTo(Ec2Service.defaultVpcId("us-east-1")))
|
||||
.body("ReplicationSubnetGroups[0].SubnetGroupStatus", equalTo("Complete"))
|
||||
.body("ReplicationSubnetGroups[0].Subnets.SubnetIdentifier", contains(SUBNET_A, SUBNET_B))
|
||||
.body("ReplicationSubnetGroups[0].Subnets.find { it.SubnetIdentifier == '"
|
||||
@@ -155,7 +156,8 @@ class DmsIntegrationTest {
|
||||
dms("CreateReplicationSubnetGroup", region)
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"tf-default-probe\","
|
||||
+ "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
|
||||
+ "\"SubnetIds\":[\"subnet-default-ap-southeast-2-a\",\"subnet-default-ap-southeast-2-b\"]}")
|
||||
+ "\"SubnetIds\":[\"" + Ec2Service.defaultSubnetId(region, "a") + "\",\""
|
||||
+ Ec2Service.defaultSubnetId(region, "b") + "\"]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -202,7 +204,7 @@ class DmsIntegrationTest {
|
||||
.statusCode(200)
|
||||
.body("ReplicationSubnetGroups", hasSize(1))
|
||||
.body("ReplicationSubnetGroups[0].ReplicationSubnetGroupIdentifier", equalTo("default"))
|
||||
.body("ReplicationSubnetGroups[0].VpcId", equalTo("vpc-default-ap-southeast-2"));
|
||||
.body("ReplicationSubnetGroups[0].VpcId", equalTo(Ec2Service.defaultVpcId("ap-southeast-2")));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,7 +232,7 @@ class DmsIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ReplicationSubnetGroups", hasSize(1))
|
||||
.body("ReplicationSubnetGroups[0].VpcId", equalTo("vpc-default-ca-central-1"));
|
||||
.body("ReplicationSubnetGroups[0].VpcId", equalTo(Ec2Service.defaultVpcId("ca-central-1")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.dms;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
@@ -31,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 = "subnet-default-us-east-1-a";
|
||||
private static final String SUBNET_B = "subnet-default-us-east-1-b";
|
||||
private static final String SUBNET_A = Ec2Service.defaultSubnetId("us-east-1", "a");
|
||||
private static final String SUBNET_B = Ec2Service.defaultSubnetId("us-east-1", "b");
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
@@ -180,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("vpc-default-us-east-1"))
|
||||
.body("ReplicationInstances[0].ReplicationSubnetGroup.VpcId", equalTo(Ec2Service.defaultVpcId("us-east-1")))
|
||||
.body("ReplicationInstances[0].EngineVersion", notNullValue());
|
||||
|
||||
dms("DeleteReplicationSubnetGroup")
|
||||
@@ -231,7 +232,7 @@ class DmsLifecycleIntegrationTest {
|
||||
describeInstance("lc-rep-default")
|
||||
.body("ReplicationInstances[0].ReplicationSubnetGroup.ReplicationSubnetGroupIdentifier",
|
||||
equalTo("default"))
|
||||
.body("ReplicationInstances[0].ReplicationSubnetGroup.VpcId", equalTo("vpc-default-us-east-1"))
|
||||
.body("ReplicationInstances[0].ReplicationSubnetGroup.VpcId", equalTo(Ec2Service.defaultVpcId("us-east-1")))
|
||||
.body("ReplicationInstances[0].ReplicationSubnetGroup.SubnetGroupStatus", equalTo("Complete"))
|
||||
.body("ReplicationInstances[0].ReplicationSubnetGroup.Subnets.SubnetIdentifier",
|
||||
hasItems(SUBNET_A, SUBNET_B));
|
||||
|
||||
@@ -83,8 +83,10 @@ class DocDbClusterSnapshotServiceTest {
|
||||
key.setEnabled(true);
|
||||
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)));
|
||||
docDbService = new DocDbService(config, new RegionResolver("us-east-1", "000000000000"), containerManager,
|
||||
storageFactory, mock(RdsService.class), mock(Ec2Service.class), kmsService);
|
||||
storageFactory, mock(RdsService.class), ec2Service, kmsService);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -68,6 +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)));
|
||||
kmsService = Mockito.mock(KmsService.class);
|
||||
when(kmsService.describeKey(any(), any())).thenThrow(new AwsException("NotFoundException", "Key not found", 404));
|
||||
when(rdsService.isManagedClusterParameterGroup(any())).thenAnswer(inv ->
|
||||
|
||||
@@ -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", "subnet-default-us-east-1-a")
|
||||
.formParam("LaunchTemplateConfig.1.Overrides.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "a"))
|
||||
.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", "subnet-default-us-east-1-b")
|
||||
.formParam("LaunchTemplateConfig.1.Overrides.1.SubnetId", Ec2Service.defaultSubnetId("us-east-1", "b"))
|
||||
.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("subnet-default-us-east-1-b"))
|
||||
equalTo(Ec2Service.defaultSubnetId("us-east-1", "b")))
|
||||
.body("CreateFleetResponse.fleetInstanceSet.item.launchTemplateAndOverrides.overrides.subnetId",
|
||||
equalTo("subnet-default-us-east-1-b"))
|
||||
equalTo(Ec2Service.defaultSubnetId("us-east-1", "b")))
|
||||
.body("CreateFleetResponse.fleetInstanceSet.item.launchTemplateAndOverrides.overrides.availabilityZone",
|
||||
equalTo("us-east-1b"));
|
||||
}
|
||||
|
||||
@@ -660,7 +660,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 'vpc-default-us-east-1' does not exist", 400));
|
||||
"InvalidVpcID.NotFound", "The vpc ID '" + Ec2Service.defaultVpcId("us-east-1") + "' does not exist", 400));
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("GroupName", "test");
|
||||
params.putSingle("GroupDescription", "test");
|
||||
|
||||
@@ -20,7 +20,7 @@ import io.floci.aws.services.ec2.model.GroupIdentifier;
|
||||
import io.floci.aws.services.ec2.model.Image;
|
||||
import io.floci.aws.services.ec2.model.Instance;
|
||||
import io.floci.aws.services.ec2.model.InstanceState;
|
||||
import io.floci.aws.services.ec2.model.IpPermission;
|
||||
import io.floci.aws.services.ec2.model.InternetGateway;
|
||||
import io.floci.aws.services.ec2.model.IpPermission;
|
||||
import io.floci.aws.services.ec2.model.IpRange;
|
||||
import io.floci.aws.services.ec2.model.Ipv6Range;
|
||||
@@ -30,6 +30,7 @@ import io.floci.aws.services.ec2.model.LaunchTemplateData;
|
||||
import io.floci.aws.services.ec2.model.ManagedPrefixList;
|
||||
import io.floci.aws.services.ec2.model.NatGateway;
|
||||
import io.floci.aws.services.ec2.model.NatGatewayAddress;
|
||||
import io.floci.aws.services.ec2.model.NetworkAcl;
|
||||
import io.floci.aws.services.ec2.model.NetworkInterface;
|
||||
import io.floci.aws.services.ec2.model.NetworkInterfaceAssociation;
|
||||
import io.floci.aws.services.ec2.model.NetworkInterfaceListResult;
|
||||
@@ -39,9 +40,9 @@ import io.floci.aws.services.ec2.model.PrefixList;
|
||||
import io.floci.aws.services.ec2.model.PrefixListEntry;
|
||||
import io.floci.aws.services.ec2.model.PrefixListId;
|
||||
import io.floci.aws.services.ec2.model.Reservation;
|
||||
import io.floci.aws.services.ec2.model.RouteTable;
|
||||
import io.floci.aws.services.ec2.model.SecurityGroup;
|
||||
import io.floci.aws.services.ec2.model.SecurityGroupRule;
|
||||
import io.floci.aws.services.ec2.model.SecurityGroupRule;
|
||||
import io.floci.aws.services.ec2.model.Snapshot;
|
||||
import io.floci.aws.services.ec2.model.Subnet;
|
||||
import io.floci.aws.services.ec2.model.Tag;
|
||||
@@ -4373,6 +4374,84 @@ class Ec2ServiceTest {
|
||||
assertEquals(Ec2Service.defaultSecurityGroupId("eu-west-1"), euWestSg.getGroupId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultNetworkResourceIdsHaveEc2ShapeAndAreRegionUniqueAndStable() {
|
||||
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
|
||||
mock(Ec2PortForwardManager.class),
|
||||
mock(AmiImageResolver.class), mock(Ec2ImageCatalog.class), new Ec2InstanceTypeCatalog(),
|
||||
new InMemoryStorageFactory());
|
||||
|
||||
for (String region : List.of("us-east-1", "eu-west-1")) {
|
||||
InternetGateway igw = service.describeInternetGateways(region, List.of(), Map.of()).getFirst();
|
||||
assertTrue(igw.getInternetGatewayId().startsWith("igw-"));
|
||||
assertTrue(isHex17(igw.getInternetGatewayId().substring(4)));
|
||||
|
||||
List<RouteTable> rts = service.describeRouteTables(region, List.of(), Map.of());
|
||||
RouteTable mainRt = rts.isEmpty() ? null : rts.getFirst();
|
||||
assertTrue(mainRt.getRouteTableId().startsWith("rtb-"));
|
||||
assertTrue(isHex17(mainRt.getRouteTableId().substring(4)));
|
||||
assertTrue(mainRt.getAssociations().stream().allMatch(a ->
|
||||
a.getRouteTableAssociationId().startsWith("rtbassoc-")
|
||||
&& isHex17(a.getRouteTableAssociationId().substring(9))));
|
||||
|
||||
List<NetworkAcl> acls = service.describeNetworkAcls(region, List.of(), Map.of());
|
||||
NetworkAcl defaultAcl = acls.stream().filter(NetworkAcl::isDefault).findFirst().orElse(acls.getFirst());
|
||||
assertTrue(defaultAcl.getNetworkAclId().startsWith("acl-"));
|
||||
assertTrue(isHex17(defaultAcl.getNetworkAclId().substring(4)));
|
||||
assertTrue(defaultAcl.getAssociations().stream().allMatch(a ->
|
||||
a.getNetworkAclAssociationId().startsWith("aclassoc-")
|
||||
&& isHex17(a.getNetworkAclAssociationId().substring(9))));
|
||||
|
||||
Vpc vpc = service.describeVpcs(region, List.of(), Map.of()).getFirst();
|
||||
assertTrue(vpc.getCidrBlockAssociationSet().stream().allMatch(c ->
|
||||
c.getAssociationId().startsWith("vpc-cidr-assoc-")
|
||||
&& isHex17(c.getAssociationId().substring("vpc-cidr-assoc-".length()))));
|
||||
}
|
||||
|
||||
// uniqueness across regions, for every default resource type
|
||||
List<String> usEastIds = defaultResourceIds(service, "us-east-1");
|
||||
List<String> euWestIds = defaultResourceIds(service, "eu-west-1");
|
||||
assertTrue(usEastIds.stream().noneMatch(euWestIds::contains),
|
||||
"default resource ids must not collide across regions: " + usEastIds + " vs " + euWestIds);
|
||||
|
||||
// stability across two seeding runs (new storage)
|
||||
Ec2Service service2 = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
|
||||
mock(Ec2PortForwardManager.class),
|
||||
mock(AmiImageResolver.class), mock(Ec2ImageCatalog.class), new Ec2InstanceTypeCatalog(),
|
||||
new InMemoryStorageFactory());
|
||||
assertEquals(usEastIds, defaultResourceIds(service2, "us-east-1"));
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
ids.add(service.describeInternetGateways(region, List.of(), Map.of()).getFirst().getInternetGatewayId());
|
||||
RouteTable rt = service.describeRouteTables(region, List.of(), Map.of()).getFirst();
|
||||
ids.add(rt.getRouteTableId());
|
||||
ids.add(rt.getAssociations().getFirst().getRouteTableAssociationId());
|
||||
NetworkAcl acl = service.describeNetworkAcls(region, List.of(), Map.of()).stream()
|
||||
.filter(NetworkAcl::isDefault).findFirst().orElseThrow();
|
||||
ids.add(acl.getNetworkAclId());
|
||||
ids.add(acl.getAssociations().getFirst().getNetworkAclAssociationId());
|
||||
ids.add(service.describeVpcs(region, List.of(), Map.of()).getFirst()
|
||||
.getCidrBlockAssociationSet().getFirst().getAssociationId());
|
||||
return ids;
|
||||
}
|
||||
|
||||
private static boolean isHex17(String s) {
|
||||
if (s == null || s.length() != 17) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveDefaultVpcIdFallsBackToPreRegionScopingStorage() throws Exception {
|
||||
// Existing regions are not re-seeded, so persisted VPCs can still have the old unscoped id.
|
||||
|
||||
+1
-1
@@ -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 = "subnet-default-us-east-1-a";
|
||||
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a");
|
||||
private static final int PORT = 8080;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.ecs;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.services.ecs.model.ClusterSetting;
|
||||
import io.floci.aws.testing.CfnStackWaits;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
@@ -56,8 +57,8 @@ class EcsContainerInsightsIntegrationTest {
|
||||
"Service": {"Type": "AWS::ECS::Service", "Properties": {"ServiceName": "web",
|
||||
"Cluster": {"Ref": "Cluster"}, "TaskDefinition": {"Ref": "TaskDef"},
|
||||
"DesiredCount": 1, "LaunchType": "FARGATE", "NetworkConfiguration": {"AwsvpcConfiguration":
|
||||
{"Subnets": ["subnet-default-us-east-1-a"]}}}}}}
|
||||
""".formatted(cluster);
|
||||
{"Subnets": ["%2$s"]}}}}}}
|
||||
""".formatted(cluster, Ec2Service.defaultSubnetId("us-east-1", "a"));
|
||||
|
||||
given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.ecs;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.path.json.config.JsonPathConfig;
|
||||
@@ -116,9 +117,9 @@ class EcsDescribeServicesIntegrationTest {
|
||||
Response created = call("CreateService", """
|
||||
{"cluster":"blue-running-cluster","serviceName":"blue-running-service",
|
||||
"taskDefinition":"blue-running-task","desiredCount":1,"launchType":"FARGATE",
|
||||
"networkConfiguration":{"awsvpcConfiguration":{"subnets":["subnet-default-us-east-1-a"]}},
|
||||
"networkConfiguration":{"awsvpcConfiguration":{"subnets":["%s"]}},
|
||||
"deploymentController":{"type":"CODE_DEPLOY"}}
|
||||
""");
|
||||
""".formatted(Ec2Service.defaultSubnetId("us-east-1", "a")));
|
||||
String primaryId = created.path("service.taskSets[0].id");
|
||||
await().atMost(Duration.ofSeconds(30)).untilAsserted(() ->
|
||||
describe("blue-running-cluster", "blue-running-service").then()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.ecs;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
@@ -40,7 +41,7 @@ class EcsExecuteCommandIntegrationTest {
|
||||
private static final String CLUSTER = "exec-cluster";
|
||||
private static final String NETWORK =
|
||||
"\"networkConfiguration\":{\"awsvpcConfiguration\":{\"subnets\":"
|
||||
+ "[\"subnet-default-us-east-1-a\"]}}";
|
||||
+ "[\"" + Ec2Service.defaultSubnetId("us-east-1", "a") + "\"]}}";
|
||||
|
||||
@BeforeAll
|
||||
static void configure() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.ecs;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
@@ -37,7 +38,7 @@ class EcsFargateEdgeCaseIntegrationTest {
|
||||
private static final String CLUSTER = "fargate-edge-cluster";
|
||||
private static final String NETWORK =
|
||||
"\"networkConfiguration\":{\"awsvpcConfiguration\":{\"subnets\":"
|
||||
+ "[\"subnet-default-us-east-1-a\"]}}";
|
||||
+ "[\"" + Ec2Service.defaultSubnetId("us-east-1", "a") + "\"]}}";
|
||||
|
||||
@BeforeAll
|
||||
static void configure() {
|
||||
@@ -446,7 +447,7 @@ class EcsFargateEdgeCaseIntegrationTest {
|
||||
|
||||
call("RunTask", "{\"cluster\":\"" + CLUSTER + "\",\"taskDefinition\":\"" + family
|
||||
+ "\",\"launchType\":\"FARGATE\",\"networkConfiguration\":{\"awsvpcConfiguration\":"
|
||||
+ "{\"subnets\":[\"subnet-default-us-east-1-a\"],\"securityGroups\":[\"sg-nope\"]}}}", 400)
|
||||
+ "{\"subnets\":[\"" + Ec2Service.defaultSubnetId("us-east-1", "a") + "\"],\"securityGroups\":[\"sg-nope\"]}}}", 400)
|
||||
.then()
|
||||
.body("__type", containsString("InvalidParameterException"))
|
||||
.body("message", containsString("sg-nope"));
|
||||
@@ -778,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\":"
|
||||
+ "[\"subnet-default-us-east-1-b\"]}}}", 200);
|
||||
+ "[\"" + Ec2Service.defaultSubnetId("us-east-1", "b") + "\"]}}}", 200);
|
||||
assertNotEquals(initial, deploymentId("edge-roll-svc"),
|
||||
"a changed network configuration must roll the deployment");
|
||||
|
||||
@@ -1070,7 +1071,7 @@ class EcsFargateEdgeCaseIntegrationTest {
|
||||
+ "\"launchType\":\"FARGATE\",\"externalId\":\"d-EXAMPLE\","
|
||||
+ "\"scale\":{\"value\":50,\"unit\":\"PERCENT\"},"
|
||||
+ "\"networkConfiguration\":{\"awsvpcConfiguration\":{\"subnets\":"
|
||||
+ "[\"subnet-default-us-east-1-a\"]}},"
|
||||
+ "[\"" + Ec2Service.defaultSubnetId("us-east-1", "a") + "\"]}},"
|
||||
+ "\"loadBalancers\":[{\"targetGroupArn\":\"arn:aws:elasticloadbalancing:us-east-1:"
|
||||
+ "000000000000:targetgroup/tg/1\",\"containerName\":\"app\",\"containerPort\":80}],"
|
||||
+ "\"tags\":[{\"key\":\"team\",\"value\":\"platform\"}]}", 200);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.ecs;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
@@ -31,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 = "subnet-default-us-east-1-a";
|
||||
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a");
|
||||
private static final String NETWORK =
|
||||
"\"networkConfiguration\":{\"awsvpcConfiguration\":{\"subnets\":[\"" + SUBNET + "\"]}}";
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.ecs;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
@@ -457,10 +458,10 @@ class EcsIntegrationTest {
|
||||
"cluster": "%s",
|
||||
"taskDefinition": "%s",
|
||||
"launchType": "FARGATE",
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["subnet-default-us-east-1-a"]}},
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}},
|
||||
"count": 1
|
||||
}
|
||||
""".formatted(CLUSTER_NAME, TASK_DEF_FAMILY))
|
||||
""".formatted(CLUSTER_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a")))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -547,10 +548,10 @@ class EcsIntegrationTest {
|
||||
"cluster": "%s",
|
||||
"taskDefinition": "empty-containers-task",
|
||||
"launchType": "FARGATE",
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["subnet-default-us-east-1-a"]}},
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}},
|
||||
"count": 1
|
||||
}
|
||||
""".formatted(CLUSTER_NAME))
|
||||
""".formatted(CLUSTER_NAME, Ec2Service.defaultSubnetId("us-east-1", "a")))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -701,13 +702,13 @@ class EcsIntegrationTest {
|
||||
"taskDefinition": "%s",
|
||||
"desiredCount": 1,
|
||||
"launchType": "FARGATE",
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["subnet-default-us-east-1-a"]}},
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}},
|
||||
"tags": [
|
||||
{"key": "Environment", "value": "dev"},
|
||||
{"key": "Project", "value": "project1"}
|
||||
]
|
||||
}
|
||||
""".formatted(CLUSTER_NAME, SERVICE_NAME, TASK_DEF_FAMILY))
|
||||
""".formatted(CLUSTER_NAME, SERVICE_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a")))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -796,9 +797,9 @@ class EcsIntegrationTest {
|
||||
"taskDefinition": "%s",
|
||||
"desiredCount": 2,
|
||||
"launchType": "FARGATE",
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["subnet-default-us-east-1-a"]}}
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}}
|
||||
}
|
||||
""".formatted(CLUSTER_NAME, SERVICE_NAME, TASK_DEF_FAMILY))
|
||||
""".formatted(CLUSTER_NAME, SERVICE_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a")))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -818,9 +819,9 @@ class EcsIntegrationTest {
|
||||
"taskDefinition": "%s",
|
||||
"desiredCount": 99,
|
||||
"launchType": "FARGATE",
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["subnet-default-us-east-1-a"]}}
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}}
|
||||
}
|
||||
""".formatted(CLUSTER_NAME, SERVICE_NAME, TASK_DEF_FAMILY))
|
||||
""".formatted(CLUSTER_NAME, SERVICE_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a")))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -842,9 +843,9 @@ class EcsIntegrationTest {
|
||||
"taskDefinition": "%s",
|
||||
"desiredCount": -5,
|
||||
"launchType": "FARGATE",
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["subnet-default-us-east-1-a"]}}
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}}
|
||||
}
|
||||
""".formatted(CLUSTER_NAME, TASK_DEF_FAMILY))
|
||||
""".formatted(CLUSTER_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a")))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -885,9 +886,9 @@ class EcsIntegrationTest {
|
||||
"taskDefinition": "%s",
|
||||
"desiredCount": 0,
|
||||
"launchType": "FARGATE",
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["subnet-default-us-east-1-a"]}}
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}}
|
||||
}
|
||||
""".formatted(CLUSTER_NAME, TASK_DEF_FAMILY))
|
||||
""".formatted(CLUSTER_NAME, TASK_DEF_FAMILY, Ec2Service.defaultSubnetId("us-east-1", "a")))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -1112,9 +1113,9 @@ class EcsIntegrationTest {
|
||||
"taskDefinition": "review-td",
|
||||
"desiredCount": 1,
|
||||
"launchType": "FARGATE",
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["subnet-default-us-east-1-a"]}}
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}}
|
||||
}
|
||||
""".formatted(REVIEW_CLUSTER, REVIEW_SERVICE))
|
||||
""".formatted(REVIEW_CLUSTER, REVIEW_SERVICE, Ec2Service.defaultSubnetId("us-east-1", "a")))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -1198,7 +1199,7 @@ class EcsIntegrationTest {
|
||||
"taskDefinition": "review-td",
|
||||
"desiredCount": 1,
|
||||
"launchType": "FARGATE",
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["subnet-default-us-east-1-a"]}},
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}},
|
||||
"loadBalancers": [
|
||||
{
|
||||
"targetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/tg-a/1234",
|
||||
@@ -1207,7 +1208,7 @@ class EcsIntegrationTest {
|
||||
}
|
||||
]
|
||||
}
|
||||
""".formatted(REVIEW_CLUSTER, REVIEW_LB_SERVICE))
|
||||
""".formatted(REVIEW_CLUSTER, REVIEW_LB_SERVICE, Ec2Service.defaultSubnetId("us-east-1", "a")))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -1223,7 +1224,7 @@ class EcsIntegrationTest {
|
||||
"taskDefinition": "review-td",
|
||||
"desiredCount": 1,
|
||||
"launchType": "FARGATE",
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["subnet-default-us-east-1-a"]}},
|
||||
"networkConfiguration": {"awsvpcConfiguration": {"subnets": ["%s"]}},
|
||||
"loadBalancers": [
|
||||
{
|
||||
"targetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:000000000000:targetgroup/tg-DIFFERENT/9999",
|
||||
@@ -1232,7 +1233,7 @@ class EcsIntegrationTest {
|
||||
}
|
||||
]
|
||||
}
|
||||
""".formatted(REVIEW_CLUSTER, REVIEW_LB_SERVICE))
|
||||
""".formatted(REVIEW_CLUSTER, REVIEW_LB_SERVICE, Ec2Service.defaultSubnetId("us-east-1", "a")))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@ import com.github.dockerjava.api.model.ContainerNetwork;
|
||||
import io.floci.aws.services.cloudmap.CloudMapService;
|
||||
import io.floci.aws.services.cloudmap.model.Operation;
|
||||
import io.floci.aws.services.cloudmap.model.Service;
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.services.ecs.model.AwsVpcConfiguration;
|
||||
import io.floci.aws.services.ecs.model.ContainerDefinition;
|
||||
import io.floci.aws.services.ecs.model.CreateServiceRequest;
|
||||
@@ -44,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
class EcsServiceDiscoveryDockerIntegrationTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String SUBNET = "subnet-default-us-east-1-a";
|
||||
private static final String SUBNET = Ec2Service.defaultSubnetId("us-east-1", "a");
|
||||
private static final String BUSYBOX_IMAGE = TestImages.BUSYBOX;
|
||||
private static final String CONTAINER_NAME = "app";
|
||||
private static final String CLOUD_MAP_SERVICE_NAME = "cache";
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.ecs;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -141,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("subnet-default-us-east-1-a")).build());
|
||||
.subnets(Ec2Service.defaultSubnetId("us-east-1", "a"))).build());
|
||||
if (provider == null) {
|
||||
request.launchType("FARGATE");
|
||||
} else {
|
||||
|
||||
@@ -79,7 +79,7 @@ class EcsTaskMetadataControllerTest {
|
||||
|
||||
private static Subnet subnet() {
|
||||
Subnet subnet = new Subnet();
|
||||
subnet.setSubnetId("subnet-default-us-east-1-a");
|
||||
subnet.setSubnetId(Ec2Service.defaultSubnetId("us-east-1", "a"));
|
||||
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("subnet-default-us-east-1-a"));
|
||||
awsvpc.setSubnets(List.of(Ec2Service.defaultSubnetId("us-east-1", "a")));
|
||||
NetworkConfiguration networkConfiguration = new NetworkConfiguration();
|
||||
networkConfiguration.setAwsvpcConfiguration(awsvpc);
|
||||
task.setNetworkConfiguration(networkConfiguration);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.elbv2;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -87,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("subnet-default-us-east-1-a", "subnet-default-us-east-1-b")))
|
||||
.type("application").subnets(List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"))))
|
||||
.loadBalancers().get(0).loadBalancerArn();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.elbv2;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -26,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("subnet-default-us-east-1-a", "subnet-default-us-east-1-b")))
|
||||
.type("application").subnets(List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"))))
|
||||
.loadBalancers().get(0).loadBalancerArn();
|
||||
try {
|
||||
String listener = client.createListener(r -> r.loadBalancerArn(balancer).port(8080).protocol("HTTP")
|
||||
|
||||
+6
-5
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.eventbridge;
|
||||
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
@@ -69,15 +70,15 @@ class EventBridgeEcsRunTaskIntegrationTest {
|
||||
"Group": "eb-ecs-group-%s",
|
||||
"NetworkConfiguration": {
|
||||
"awsvpcConfiguration": {
|
||||
"Subnets": ["subnet-default-us-east-1-a", "subnet-default-us-east-1-b"],
|
||||
"SecurityGroups": ["sg-default-us-east-1"],
|
||||
"Subnets": ["%s", "%s"],
|
||||
"SecurityGroups": ["%s"],
|
||||
"AssignPublicIp": "ENABLED"
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
""".formatted(ruleName, clusterArn, taskDefinitionArn, suffix))
|
||||
""".formatted(ruleName, clusterArn, taskDefinitionArn, suffix, Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"), Ec2Service.defaultSecurityGroupId("us-east-1")))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -100,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("subnet-default-us-east-1-a"))
|
||||
hasItem(Ec2Service.defaultSubnetId("us-east-1", "a")))
|
||||
.body("Targets[0].EcsParameters.NetworkConfiguration.awsvpcConfiguration.SecurityGroups",
|
||||
hasItem("sg-default-us-east-1"))
|
||||
hasItem(Ec2Service.defaultSecurityGroupId("us-east-1")))
|
||||
.body("Targets[0].EcsParameters.NetworkConfiguration.awsvpcConfiguration.AssignPublicIp",
|
||||
equalTo("ENABLED"));
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.floci.aws.services.iam;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.testing.EnforcementFixtures;
|
||||
import io.floci.aws.testing.IamEnforcementProfile;
|
||||
import io.floci.aws.testing.PartitionCleanup;
|
||||
@@ -1102,16 +1103,17 @@ class IamPassRoleEnforcementIntegrationTest {
|
||||
private static String runTask(String cluster, String family, String taskRoleOverride) {
|
||||
return """
|
||||
{"cluster":"%s","taskDefinition":"%s","launchType":"FARGATE","count":1,
|
||||
"networkConfiguration":{"awsvpcConfiguration":{"subnets":["subnet-default-us-east-1-a"]}}%s}"""
|
||||
.formatted(cluster, family, taskRoleOverride == null ? ""
|
||||
"networkConfiguration":{"awsvpcConfiguration":{"subnets":["%s"]}}%s}"""
|
||||
.formatted(cluster, family, Ec2Service.defaultSubnetId("us-east-1", "a"),
|
||||
taskRoleOverride == null ? ""
|
||||
: ",\"overrides\":{\"taskRoleArn\":\"" + taskRoleOverride + "\"}");
|
||||
}
|
||||
|
||||
private static String service(String cluster, String name, String family) {
|
||||
return """
|
||||
{"cluster":"%s","serviceName":"%s","taskDefinition":"%s","desiredCount":0,"launchType":"FARGATE",
|
||||
"networkConfiguration":{"awsvpcConfiguration":{"subnets":["subnet-default-us-east-1-a"]}}}"""
|
||||
.formatted(cluster, name, family);
|
||||
"networkConfiguration":{"awsvpcConfiguration":{"subnets":["%s"]}}}"""
|
||||
.formatted(cluster, name, family, Ec2Service.defaultSubnetId("us-east-1", "a"));
|
||||
}
|
||||
|
||||
private static RequestSpecification createStack(User user, String stack) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.floci.aws.services.rds;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.services.docdb.DocDbQueryHandler;
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.services.neptune.NeptuneQueryHandler;
|
||||
import io.floci.aws.services.rds.export.RdsExportTaskService;
|
||||
import io.floci.aws.services.rds.model.DatabaseEngine;
|
||||
@@ -3526,8 +3527,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("subnet-default-a", "subnet-default-b"));
|
||||
group.setSubnetAvailabilityZones(Map.of("subnet-default-a", "us-east-1a", "subnet-default-b", "us-east-1b"));
|
||||
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"));
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,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("subnet-default-a", "subnet-default-b");
|
||||
List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"));
|
||||
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));
|
||||
@@ -3074,7 +3074,7 @@ class RdsServiceTest {
|
||||
|
||||
@Test
|
||||
void createDbInstanceOmittedPubliclyAccessibleDefaultsFalseForNamedNonDefaultSubnetGroup() {
|
||||
rdsService.createDbSubnetGroup("custom-subnets", "test", List.of("subnet-default-a", "subnet-default-b"));
|
||||
rdsService.createDbSubnetGroup("custom-subnets", "test", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
|
||||
|
||||
DbInstance instance = rdsService.createDbInstance("custom-subnet-db", "postgres", "13",
|
||||
"admin", "password", "dbname", "db.t3.micro",
|
||||
@@ -4969,10 +4969,10 @@ class RdsServiceTest {
|
||||
@Test
|
||||
void dbSubnetGroupRoundTrip() {
|
||||
DbSubnetGroup group = rdsService.createDbSubnetGroup(
|
||||
"sample-db-subnets", "test", List.of("subnet-default-a", "subnet-default-b"));
|
||||
"sample-db-subnets", "test", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
|
||||
|
||||
assertEquals("sample-db-subnets", group.getDbSubnetGroupName());
|
||||
assertEquals(List.of("subnet-default-a", "subnet-default-b"), group.getSubnetIds());
|
||||
assertEquals(List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")), group.getSubnetIds());
|
||||
assertEquals(1, rdsService.listDbSubnetGroups("sample-db-subnets").size());
|
||||
|
||||
rdsService.deleteDbSubnetGroup("sample-db-subnets");
|
||||
@@ -5000,7 +5000,7 @@ class RdsServiceTest {
|
||||
@Test
|
||||
void dbSubnetGroupTagsRoundTripAndMutateByArn() {
|
||||
rdsService.createDbSubnetGroup(
|
||||
"sample-db-subnets", "test", List.of("subnet-default-a", "subnet-default-b"));
|
||||
"sample-db-subnets", "test", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
|
||||
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)
|
||||
@@ -5018,11 +5018,11 @@ class RdsServiceTest {
|
||||
@Test
|
||||
void dbSubnetGroupTagsSurviveModify() {
|
||||
rdsService.createDbSubnetGroup(
|
||||
"sample-db-subnets", "test", List.of("subnet-default-a", "subnet-default-b"));
|
||||
"sample-db-subnets", "test", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
|
||||
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("subnet-default-a"));
|
||||
rdsService.modifyDbSubnetGroup("sample-db-subnets", List.of(Ec2Service.defaultSubnetId("us-east-1", "a")));
|
||||
|
||||
assertEquals(Map.of("Name", "sample-db-subnets"),
|
||||
rdsService.listTagsForResource(arn));
|
||||
@@ -6652,7 +6652,7 @@ class RdsServiceTest {
|
||||
new InMemoryStorage<>();
|
||||
DbSubnetGroup subnetGroup = new DbSubnetGroup(
|
||||
"legacy-subnets", "legacy", "vpc-default", PROXY_SUBNET_IDS,
|
||||
Map.of("subnet-default-a", "us-east-1a", "subnet-default-b", "us-east-1b"));
|
||||
Map.of(Ec2Service.defaultSubnetId("us-east-1", "a"), "us-east-1a", Ec2Service.defaultSubnetId("us-east-1", "b"), "us-east-1b"));
|
||||
subnetGroup.setDbSubnetGroupArn(
|
||||
"arn:aws:rds:us-east-1:" + accountId + ":subgrp:legacy-subnets");
|
||||
rawSubnetGroups.put("legacy-subnets", subnetGroup);
|
||||
@@ -6752,10 +6752,10 @@ class RdsServiceTest {
|
||||
|
||||
@Test
|
||||
void createDbSubnetGroupRejectsDuplicateWithModelCode() {
|
||||
rdsService.createDbSubnetGroup("my-subnet-group", "desc", List.of("subnet-default-a", "subnet-default-b"));
|
||||
rdsService.createDbSubnetGroup("my-subnet-group", "desc", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.createDbSubnetGroup("my-subnet-group", "desc", List.of("subnet-default-a", "subnet-default-b")));
|
||||
rdsService.createDbSubnetGroup("my-subnet-group", "desc", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b"))));
|
||||
|
||||
assertEquals("DBSubnetGroupAlreadyExists", exception.getErrorCode());
|
||||
}
|
||||
@@ -6763,7 +6763,7 @@ class RdsServiceTest {
|
||||
@Test
|
||||
void createDbSubnetGroupPopulatesArn() {
|
||||
DbSubnetGroup group = rdsService.createDbSubnetGroup("my-subnet-group", "desc",
|
||||
List.of("subnet-default-a", "subnet-default-b"));
|
||||
List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
|
||||
|
||||
assertEquals("arn:aws:rds:us-east-1:123456789012:subgrp:my-subnet-group", group.getDbSubnetGroupArn());
|
||||
}
|
||||
@@ -6829,7 +6829,7 @@ class RdsServiceTest {
|
||||
|
||||
@Test
|
||||
void resolveDbSubnetGroupViewReturnsStoredCustomGroup() {
|
||||
rdsService.createDbSubnetGroup("my-subnet-group", "desc", List.of("subnet-default-a", "subnet-default-b"));
|
||||
rdsService.createDbSubnetGroup("my-subnet-group", "desc", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")));
|
||||
|
||||
DbSubnetGroup group = rdsService.resolveDbSubnetGroupView("my-subnet-group");
|
||||
|
||||
@@ -11443,8 +11443,8 @@ class RdsServiceTest {
|
||||
|
||||
private static List<Subnet> defaultSubnets() {
|
||||
return List.of(
|
||||
subnet("subnet-default-a", "vpc-default", "us-east-1a"),
|
||||
subnet("subnet-default-b", "vpc-default", "us-east-1b"));
|
||||
subnet(Ec2Service.defaultSubnetId("us-east-1", "a"), "vpc-default", "us-east-1a"),
|
||||
subnet(Ec2Service.defaultSubnetId("us-east-1", "b"), "vpc-default", "us-east-1b"));
|
||||
}
|
||||
|
||||
private static DbInstance persistedInstance(
|
||||
@@ -11520,7 +11520,7 @@ class RdsServiceTest {
|
||||
|
||||
@Test
|
||||
void createDbSubnetGroupStoresTheTagsItIsGiven() {
|
||||
rdsService.createDbSubnetGroup("tagged", "d", List.of("subnet-default-a", "subnet-default-b"), "us-east-1",
|
||||
rdsService.createDbSubnetGroup("tagged", "d", List.of(Ec2Service.defaultSubnetId("us-east-1", "a"), Ec2Service.defaultSubnetId("us-east-1", "b")), "us-east-1",
|
||||
Map.of("Name", "tagged", "env", "tst"));
|
||||
String arn = "arn:aws:rds:us-east-1:123456789012:subgrp:tagged";
|
||||
|
||||
@@ -11538,7 +11538,7 @@ class RdsServiceTest {
|
||||
|
||||
@Test
|
||||
void createDbSubnetGroupErrorNamesMissingSubnetIds() {
|
||||
String subnetA = "subnet-default-a";
|
||||
String subnetA = Ec2Service.defaultSubnetId("us-east-1", "a");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
rdsService.createDbSubnetGroup("grp", "desc",
|
||||
|
||||
Reference in new issue
Block a user