mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(ec2): give availability-zone ids AWS's shape, shared by EC2, flow logs and EFS (#5486)
* fix(efs): report the zone id EC2 reports for the same zone EFS derived its own availability-zone id (use1-az1) by splitting the region on hyphens, while EC2 publishes <region>-az<n> for subnets and zones, so a mount target and its subnet disagreed. The abbreviation also only worked for three-part regions: us-gov-west-1a and eusc-de-east-1a kept the whole region. EFS now takes the id from the helper EC2 and VPC flow logs use. Also drops an allowlist pattern for flow-log region abbreviations that matches no source line since flow logs moved to the same helper. Signed-off-by: Hector Ventura <hectorvent@gmail.com> * fix(ec2): give availability-zone ids AWS's shape, shared by EC2, flow logs and EFS EC2 published <region>-az<n> as a zone id and EFS its own abbreviation, so a mount target and its subnet disagreed and neither matched AWS in every region. AvailabilityZoneIds in core.common now derives the id for all three: AWS's short region prefix and -az<n> (use1-az1, apne1-az1, usgw1-az1, cnn1-az1). The prefix rule is attested for the commercial, China and GovCloud regions; AWS publishes no zone id for an ISO or EUSC region, so those keep the whole region as the prefix instead of a guessed one. Zone a is still az1, b az2, and so on: AWS maps names to ids per account, which Floci does not model. CreateSubnet resolves AvailabilityZoneId in the new shape and refuses the old one. Signed-off-by: Hector Ventura <hectorvent@gmail.com> --------- Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
78377921e3
commit
1aabc8b4fe
11 files changed
+191
-75
No files matched your search
@@ -233,6 +233,9 @@ the commercial value or Floci's own base host until sourced:
|
||||
- the Lambda function-URL host outside the commercial partition;
|
||||
- whether AWS managed policy documents differ in content in China or GovCloud;
|
||||
- the API Gateway regional hosted zone per region;
|
||||
- the availability-zone id prefix of the ISO and EUSC regions: zone ids there keep the whole region
|
||||
(`us-iso-east-1-az1`), where the other partitions get AWS's short prefix (`use1-az1`, `usgw1-az1`,
|
||||
`cnn1-az1`);
|
||||
- S3 `LocationConstraint` enum values and Route 53 hosted zones for the ISO and EUSC regions;
|
||||
- the SAML sign-on URL in `aws-iso-e`, `aws-iso-f` and `aws-eusc`, where assertions keep being
|
||||
checked against the commercial `https://signin.aws.amazon.com/saml`;
|
||||
|
||||
@@ -615,6 +615,13 @@ allocated address.
|
||||
| DescribeRegions | Returns the regions known to the local EC2 service. |
|
||||
| DescribeAccountAttributes | Returns local account-level EC2 attributes. |
|
||||
|
||||
A zone id has AWS's shape, a short region prefix and `-az<n>`: `use1-az1` in `us-east-1`, `apne1-az1`
|
||||
in `ap-northeast-1`, `usgw1-az1` in `us-gov-west-1`. On AWS the pairing of a zone name with a zone id
|
||||
differs per account; Floci always pairs zone `a` with `az1`, `b` with `az2`, and so on. Subnets, VPC
|
||||
flow-log records and EFS mount targets report the same id for the same zone. The ISO and EUSC
|
||||
regions, for which AWS publishes no zone id, keep the whole region as the prefix
|
||||
(`us-iso-east-1-az1`).
|
||||
|
||||
### Instance Types
|
||||
|
||||
| Action | Description |
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The availability-zone id of a zone, the way AWS writes one: a short region prefix and
|
||||
* {@code -az<n>} ({@code use1-az1}, {@code apne1-az2}, {@code usgw1-az1}, {@code cnn1-az1}). The
|
||||
* id names the same physical zone in every account; it is the zone names that AWS maps per
|
||||
* account, which is why {@code us-east-1a} is {@code use1-az1} for one account and
|
||||
* {@code use1-az4} for another. Floci has one account's view, so it pairs zone {@code a} with
|
||||
* {@code az1}, {@code b} with {@code az2}, and so on.
|
||||
*
|
||||
* <p>The prefix abbreviates the region: its first segment, the initial letters of the middle
|
||||
* ones ({@code northeast} gives {@code ne}, {@code gov} gives {@code g}) and its number. That
|
||||
* holds for the commercial, China and GovCloud regions. AWS publishes no zone id for an ISO or
|
||||
* EUSC region, so a region with a middle segment this class does not know keeps its whole name
|
||||
* as the prefix ({@code us-iso-east-1-az1}) rather than a guessed abbreviation.
|
||||
*
|
||||
* <p>EC2, VPC flow logs and EFS all derive their ids here, so a subnet, a flow-log record and a
|
||||
* mount target in one zone report the same id.
|
||||
*/
|
||||
public final class AvailabilityZoneIds {
|
||||
|
||||
private static final String SEPARATOR = "-az";
|
||||
|
||||
private static final Map<String, String> SEGMENT_INITIALS = Map.ofEntries(
|
||||
Map.entry("north", "n"), Map.entry("south", "s"), Map.entry("east", "e"),
|
||||
Map.entry("west", "w"), Map.entry("central", "c"), Map.entry("northeast", "ne"),
|
||||
Map.entry("northwest", "nw"), Map.entry("southeast", "se"), Map.entry("southwest", "sw"),
|
||||
Map.entry("gov", "g"));
|
||||
|
||||
private AvailabilityZoneIds() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The id of {@code zoneName} in {@code region}. A name that is not the region's
|
||||
* {@code <region><letter>} keeps the first zone's id.
|
||||
*/
|
||||
public static String forZoneName(String region, String zoneName) {
|
||||
if (zoneName != null && zoneName.length() == region.length() + 1 && zoneName.startsWith(region)) {
|
||||
char letter = Character.toLowerCase(zoneName.charAt(zoneName.length() - 1));
|
||||
if (letter >= 'a' && letter <= 'z') {
|
||||
return forIndex(region, letter - 'a' + 1);
|
||||
}
|
||||
}
|
||||
return forIndex(region, 1);
|
||||
}
|
||||
|
||||
/** The id of the {@code index}-th zone of {@code region}, counting from 1. */
|
||||
public static String forIndex(String region, int index) {
|
||||
return prefix(region) + SEPARATOR + index;
|
||||
}
|
||||
|
||||
/**
|
||||
* The 1-based zone index {@code zoneId} names in {@code region}, or -1 when it is not one of
|
||||
* this region's ids.
|
||||
*/
|
||||
public static int indexOf(String region, String zoneId) {
|
||||
String start = prefix(region) + SEPARATOR;
|
||||
if (zoneId == null || !zoneId.startsWith(start)) {
|
||||
return -1;
|
||||
}
|
||||
String digits = zoneId.substring(start.length());
|
||||
if (digits.isEmpty() || digits.length() > 2 || !digits.chars().allMatch(Character::isDigit)) {
|
||||
return -1;
|
||||
}
|
||||
return Integer.parseInt(digits);
|
||||
}
|
||||
|
||||
/** {@code use1} for {@code us-east-1}; the region itself where its segments are not known. */
|
||||
public static String prefix(String region) {
|
||||
String[] segments = region.split("-");
|
||||
if (segments.length < 3) {
|
||||
return region;
|
||||
}
|
||||
StringBuilder prefix = new StringBuilder(segments[0]);
|
||||
for (int i = 1; i < segments.length - 1; i++) {
|
||||
String initials = SEGMENT_INITIALS.get(segments[i]);
|
||||
if (initials == null) {
|
||||
return region;
|
||||
}
|
||||
prefix.append(initials);
|
||||
}
|
||||
return prefix.append(segments[segments.length - 1]).toString();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ec2;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AvailabilityZoneIds;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsPartition;
|
||||
@@ -1073,7 +1074,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
subnet.setCidrBlock(cidrBlocks[i]);
|
||||
subnet.setState("available");
|
||||
subnet.setAvailabilityZone(region + azSuffixes[i]);
|
||||
subnet.setAvailabilityZoneId(zoneIdForZoneName(region, region + azSuffixes[i]));
|
||||
subnet.setAvailabilityZoneId(AvailabilityZoneIds.forZoneName(region, region + azSuffixes[i]));
|
||||
subnet.setAvailableIpAddressCount(4091);
|
||||
subnet.setDefaultForAz(true);
|
||||
subnet.setMapPublicIpOnLaunch(true);
|
||||
@@ -5562,24 +5563,6 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
|
||||
// ─── Subnets ───────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* The zone id Floci publishes for a zone name. AWS's real zone ids are opaque and per-account
|
||||
* ({@code use1-az4}); Floci derives a deterministic one instead, and what matters is that
|
||||
* every surface derives it the same way, DescribeAvailabilityZones, the seeded default
|
||||
* subnets and CreateSubnet all come through here, so a subnet's zone id agrees with the zone
|
||||
* list a client just read. A zone name that is not this region's {@code <region><letter>}
|
||||
* keeps the first zone's id, which is what an unrecognised name resolved to before.
|
||||
*/
|
||||
static String zoneIdForZoneName(String region, String zoneName) {
|
||||
if (zoneName != null && zoneName.length() == region.length() + 1 && zoneName.startsWith(region)) {
|
||||
char letter = Character.toLowerCase(zoneName.charAt(zoneName.length() - 1));
|
||||
if (letter >= 'a' && letter <= 'z') {
|
||||
return region + "-az" + (letter - 'a' + 1);
|
||||
}
|
||||
}
|
||||
return region + "-az1";
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the zone a new subnet lands in from whichever of AvailabilityZone and
|
||||
* AvailabilityZoneId the caller supplied. Terraform's aws_subnet exposes both
|
||||
@@ -5601,28 +5584,21 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
|
||||
/**
|
||||
* The inverse of {@link #zoneIdForZoneName}. An id outside the zones this region publishes is
|
||||
* refused rather than resolved: placing a subnet in a zone DescribeAvailabilityZones does not
|
||||
* list would leave a client unable to pair the two, which is the same inconsistency the
|
||||
* hardcoded az1 produced, only quieter.
|
||||
* The zone name an {@link AvailabilityZoneIds} id names. An id outside the zones this region
|
||||
* publishes is refused rather than resolved: placing a subnet in a zone
|
||||
* DescribeAvailabilityZones does not list would leave a client unable to pair the two, which
|
||||
* is the same inconsistency the hardcoded az1 produced, only quieter.
|
||||
*/
|
||||
private static String zoneNameForZoneId(String region, String availabilityZoneId) {
|
||||
String prefix = region + "-az";
|
||||
if (availabilityZoneId.startsWith(prefix)) {
|
||||
try {
|
||||
int index = Integer.parseInt(availabilityZoneId.substring(prefix.length()));
|
||||
if (index >= 1 && index <= MODELLED_ZONE_SUFFIXES.length) {
|
||||
return region + MODELLED_ZONE_SUFFIXES[index - 1];
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
LOG.debugv("Availability zone ID {0} has a non-numeric zone index: {1}",
|
||||
availabilityZoneId, e.getMessage());
|
||||
}
|
||||
int index = AvailabilityZoneIds.indexOf(region, availabilityZoneId);
|
||||
if (index >= 1 && index <= MODELLED_ZONE_SUFFIXES.length) {
|
||||
return region + MODELLED_ZONE_SUFFIXES[index - 1];
|
||||
}
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid availability zone ID: '" + availabilityZoneId + "'. This region publishes "
|
||||
+ MODELLED_ZONE_SUFFIXES.length + " availability zones, " + prefix + "1 to "
|
||||
+ prefix + MODELLED_ZONE_SUFFIXES.length + ".", 400);
|
||||
+ MODELLED_ZONE_SUFFIXES.length + " availability zones, "
|
||||
+ AvailabilityZoneIds.forIndex(region, 1) + " to "
|
||||
+ AvailabilityZoneIds.forIndex(region, MODELLED_ZONE_SUFFIXES.length) + ".", 400);
|
||||
}
|
||||
|
||||
public Subnet createSubnet(String region, String vpcId, String cidrBlock, String availabilityZone) {
|
||||
@@ -5658,7 +5634,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
subnet.setCidrBlock(cidrBlock);
|
||||
subnet.setState("available");
|
||||
subnet.setAvailabilityZone(zoneName);
|
||||
subnet.setAvailabilityZoneId(zoneIdForZoneName(region, zoneName));
|
||||
subnet.setAvailabilityZoneId(AvailabilityZoneIds.forZoneName(region, zoneName));
|
||||
subnet.setAvailableIpAddressCount(251);
|
||||
String ownerAccountId = callerAccountId();
|
||||
subnet.setOwnerId(ownerAccountId);
|
||||
@@ -9271,7 +9247,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
az.put("zoneName", region + suffix);
|
||||
az.put("state", "available");
|
||||
az.put("regionName", region);
|
||||
az.put("zoneId", zoneIdForZoneName(region, region + suffix));
|
||||
az.put("zoneId", AvailabilityZoneIds.forZoneName(region, region + suffix));
|
||||
az.put("zoneType", "availability-zone");
|
||||
zones.add(az);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.ec2;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.common.AvailabilityZoneIds;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -595,11 +596,11 @@ public class FlowLogService {
|
||||
|
||||
/**
|
||||
* The zone id of the ENI's zone, derived exactly as subnets and DescribeAvailabilityZones
|
||||
* derive it ({@link Ec2Service#zoneIdForZoneName}), so a record's {@code az-id} matches the
|
||||
* derive it ({@link AvailabilityZoneIds}), so a record's {@code az-id} matches the
|
||||
* {@code AvailabilityZoneId} of the subnet it came from, in every region and partition.
|
||||
*/
|
||||
private static String azId(String region, String az) {
|
||||
return region == null ? null : Ec2Service.zoneIdForZoneName(region, az);
|
||||
return region == null ? null : AvailabilityZoneIds.forZoneName(region, az);
|
||||
}
|
||||
|
||||
private static String nz(String s) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.efs;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.common.AvailabilityZoneIds;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
@@ -121,7 +122,7 @@ public class EfsService implements Resettable {
|
||||
fs.setKmsKeyId(request.getKmsKeyId());
|
||||
if (request.getAvailabilityZoneName() != null) {
|
||||
fs.setAvailabilityZoneName(request.getAvailabilityZoneName());
|
||||
fs.setAvailabilityZoneId(generateAzId(request.getAvailabilityZoneName()));
|
||||
fs.setAvailabilityZoneId(AvailabilityZoneIds.forZoneName(region, request.getAvailabilityZoneName()));
|
||||
}
|
||||
|
||||
if (request.getTags() != null) {
|
||||
@@ -404,7 +405,7 @@ public class EfsService implements Resettable {
|
||||
mt.setLifeCycleState(LifeCycleState.available);
|
||||
mt.setVpcId("vpc-12345678");
|
||||
mt.setAvailabilityZoneName(region + "a");
|
||||
mt.setAvailabilityZoneId(generateAzId(region + "a"));
|
||||
mt.setAvailabilityZoneId(AvailabilityZoneIds.forZoneName(region, region + "a"));
|
||||
mt.setNetworkInterfaceId("eni-" + UUID.randomUUID().toString().replace("-", "").substring(0, 17));
|
||||
if (request.getSecurityGroups() != null) {
|
||||
mt.setSecurityGroups(new ArrayList<>(request.getSecurityGroups()));
|
||||
@@ -636,21 +637,4 @@ public class EfsService implements Resettable {
|
||||
private String regionKey(String region, String id) {
|
||||
return region + "::" + id;
|
||||
}
|
||||
|
||||
private String generateAzId(String azName) {
|
||||
if (azName == null || azName.length() < 2) return azName + "-id";
|
||||
String region = azName.substring(0, azName.length() - 1);
|
||||
char letter = azName.charAt(azName.length() - 1);
|
||||
int num = (letter >= 'a' && letter <= 'z') ? (letter - 'a' + 1) : 1;
|
||||
|
||||
String shortCode = region;
|
||||
String[] parts = region.split("-");
|
||||
if (parts.length == 3) {
|
||||
String mid = parts[1].replace("north", "n").replace("south", "s")
|
||||
.replace("east", "e").replace("west", "w")
|
||||
.replace("central", "c");
|
||||
shortCode = parts[0] + mid + parts[2];
|
||||
}
|
||||
return shortCode + "-az" + num;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class AvailabilityZoneIdsTest {
|
||||
|
||||
/**
|
||||
* Prefixes AWS publishes: the commercial ones from the Regions and Zones guide, China's from
|
||||
* moto's zone table, GovCloud West's from the Terraform provider's acceptance configuration.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"us-east-1, use1",
|
||||
"us-west-2, usw2",
|
||||
"ap-northeast-1, apne1",
|
||||
"ap-southeast-4, apse4",
|
||||
"eu-central-2, euc2",
|
||||
"mx-central-1, mxc1",
|
||||
"af-south-1, afs1",
|
||||
"cn-north-1, cnn1",
|
||||
"cn-northwest-1, cnnw1",
|
||||
"us-gov-west-1, usgw1",
|
||||
"us-gov-east-1, usge1"})
|
||||
void aPublishedRegionGetsAwsPrefix(String region, String prefix) {
|
||||
assertEquals(prefix, AvailabilityZoneIds.prefix(region));
|
||||
assertEquals(prefix + "-az1", AvailabilityZoneIds.forZoneName(region, region + "a"));
|
||||
assertEquals(prefix + "-az3", AvailabilityZoneIds.forZoneName(region, region + "c"));
|
||||
}
|
||||
|
||||
/** No zone id is published for these regions, so none is made up: the region is the prefix. */
|
||||
@ParameterizedTest
|
||||
@CsvSource({"us-iso-east-1", "us-isob-east-1", "eu-isoe-west-1", "us-isof-south-1", "eusc-de-east-1"})
|
||||
void aRegionWithoutAPublishedPrefixKeepsItsName(String region) {
|
||||
assertEquals(region, AvailabilityZoneIds.prefix(region));
|
||||
assertEquals(region + "-az2", AvailabilityZoneIds.forZoneName(region, region + "b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aZoneNameOutsideTheRegionKeepsTheFirstZonesId() {
|
||||
assertEquals("use1-az1", AvailabilityZoneIds.forZoneName("us-east-1", "eu-west-1b"));
|
||||
assertEquals("use1-az1", AvailabilityZoneIds.forZoneName("us-east-1", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void indexOfReadsBackTheIdsThisRegionPublishes() {
|
||||
assertEquals(2, AvailabilityZoneIds.indexOf("us-east-1", "use1-az2"));
|
||||
assertEquals(1, AvailabilityZoneIds.indexOf("us-iso-east-1", "us-iso-east-1-az1"));
|
||||
assertEquals(-1, AvailabilityZoneIds.indexOf("us-east-1", "usw2-az2"));
|
||||
assertEquals(-1, AvailabilityZoneIds.indexOf("us-east-1", "us-east-1-az2"));
|
||||
assertEquals(-1, AvailabilityZoneIds.indexOf("us-east-1", "use1-azx"));
|
||||
assertEquals(-1, AvailabilityZoneIds.indexOf("us-east-1", null));
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -11,7 +11,7 @@ import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
/**
|
||||
* CreateSubnet never read AvailabilityZoneId and hardcoded every new subnet's zone id to the
|
||||
* region's first zone, so a subnet asked for us-east-1-az2 came back in us-east-1-az1, and even
|
||||
* region's first zone, so a subnet asked for use1-az2 came back in use1-az1, and even
|
||||
* a subnet placed correctly by zone <em>name</em> reported a zone id that contradicted it.
|
||||
* Anything selecting subnets by zone id (Terraform's aws_subnet.availability_zone_id, and any
|
||||
* client pairing subnets with the DescribeAvailabilityZones list) therefore saw one zone.
|
||||
@@ -50,7 +50,7 @@ class Ec2SubnetAvailabilityZoneIdIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CreateSubnetResponse.subnet.availabilityZone", equalTo("us-east-1b"))
|
||||
.body("CreateSubnetResponse.subnet.availabilityZoneId", equalTo("us-east-1-az2"));
|
||||
.body("CreateSubnetResponse.subnet.availabilityZoneId", equalTo("use1-az2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,13 +59,13 @@ class Ec2SubnetAvailabilityZoneIdIntegrationTest {
|
||||
.formParam("Action", "CreateSubnet")
|
||||
.formParam("VpcId", vpcId)
|
||||
.formParam("CidrBlock", "10.90.2.0/24")
|
||||
.formParam("AvailabilityZoneId", "us-east-1-az3")
|
||||
.formParam("AvailabilityZoneId", "use1-az3")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CreateSubnetResponse.subnet.availabilityZoneId", equalTo("us-east-1-az3"))
|
||||
.body("CreateSubnetResponse.subnet.availabilityZoneId", equalTo("use1-az3"))
|
||||
.body("CreateSubnetResponse.subnet.availabilityZone", equalTo("us-east-1c"))
|
||||
.extract().path("CreateSubnetResponse.subnet.subnetId");
|
||||
|
||||
@@ -78,7 +78,7 @@ class Ec2SubnetAvailabilityZoneIdIntegrationTest {
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeSubnetsResponse.subnetSet.item.availabilityZoneId", equalTo("us-east-1-az3"));
|
||||
.body("DescribeSubnetsResponse.subnetSet.item.availabilityZoneId", equalTo("use1-az3"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +97,7 @@ class Ec2SubnetAvailabilityZoneIdIntegrationTest {
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CreateSubnetResponse.subnet.availabilityZoneId", equalTo("us-east-1-az3"));
|
||||
.body("CreateSubnetResponse.subnet.availabilityZoneId", equalTo("use1-az3"));
|
||||
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
@@ -107,7 +107,7 @@ class Ec2SubnetAvailabilityZoneIdIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.zoneId",
|
||||
hasItem("us-east-1-az3"));
|
||||
hasItem("use1-az3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,7 +117,7 @@ class Ec2SubnetAvailabilityZoneIdIntegrationTest {
|
||||
.formParam("VpcId", vpcId)
|
||||
.formParam("CidrBlock", "10.90.4.0/24")
|
||||
.formParam("AvailabilityZone", "us-east-1a")
|
||||
.formParam("AvailabilityZoneId", "us-east-1-az2")
|
||||
.formParam("AvailabilityZoneId", "use1-az2")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
@@ -133,7 +133,7 @@ class Ec2SubnetAvailabilityZoneIdIntegrationTest {
|
||||
.formParam("VpcId", vpcId)
|
||||
.formParam("CidrBlock", "10.90.5.0/24")
|
||||
.formParam("AvailabilityZone", "us-east-1b")
|
||||
.formParam("AvailabilityZoneId", "us-east-1-az2")
|
||||
.formParam("AvailabilityZoneId", "use1-az2")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
@@ -153,14 +153,14 @@ class Ec2SubnetAvailabilityZoneIdIntegrationTest {
|
||||
.formParam("Action", "CreateSubnet")
|
||||
.formParam("VpcId", vpcId)
|
||||
.formParam("CidrBlock", "10.90.7.0/24")
|
||||
.formParam("AvailabilityZoneId", "us-east-1-az4")
|
||||
.formParam("AvailabilityZoneId", "use1-az4")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"))
|
||||
.body("Response.Errors.Error.Message", containsString("us-east-1-az1 to us-east-1-az3"));
|
||||
.body("Response.Errors.Error.Message", containsString("use1-az1 to use1-az3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.ec2;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AvailabilityZoneIds;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.ec2.model.FlowLog;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Instance;
|
||||
@@ -183,8 +184,8 @@ class FlowLogServiceTest {
|
||||
|
||||
/**
|
||||
* A record's az-id is the zone id subnets and DescribeAvailabilityZones publish for the same
|
||||
* zone. FlowLogService once derived its own ({@code use1-az1}, and {@code cnnorth1-az1} for
|
||||
* China), so the two never agreed in any region.
|
||||
* zone. FlowLogService once derived its own, with a different rule ({@code cnnorth1-az1} for
|
||||
* China), so the two did not agree.
|
||||
*/
|
||||
@Test
|
||||
void azIdMatchesTheZoneIdEc2PublishesForTheZone() throws Exception {
|
||||
@@ -193,7 +194,7 @@ class FlowLogServiceTest {
|
||||
|
||||
assertEquals("az-id", lines.get(0));
|
||||
for (String row : records(lines)) {
|
||||
assertEquals(Ec2Service.zoneIdForZoneName(region, region + "a"), row, "in " + region);
|
||||
assertEquals(AvailabilityZoneIds.forZoneName(region, region + "a"), row, "in " + region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,9 @@ class EfsIntegrationTest {
|
||||
.body("MountTargetId", startsWith("fsmt-"))
|
||||
.body("FileSystemId", equalTo(fileSystemId))
|
||||
.body("SubnetId", equalTo("subnet-12345"))
|
||||
.body("AvailabilityZoneName", equalTo("us-east-1a"))
|
||||
// The zone id EC2 reports for the same zone, so a mount target agrees with its subnet.
|
||||
.body("AvailabilityZoneId", equalTo("use1-az1"))
|
||||
.extract().jsonPath().getString("MountTargetId");
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ patterns:
|
||||
- regex: acs\.amazonaws\.com/groups/
|
||||
reason: S3 canned-ACL grantee URIs (AllUsers, AuthenticatedUsers, LogDelivery) are
|
||||
partition-invariant identifiers in the S3 model.
|
||||
- regex: 'case "[a-z]{2}-[a-z]+-\d" -> "[a-z]{3,5}\d";'
|
||||
reason: VPC Flow Logs' documented region abbreviations (use1, euw1, ...).
|
||||
- regex: \bPARTITION_REGEX\b
|
||||
reason: the line builds its regex from AwsArnUtils.PARTITION_REGEX, which is the
|
||||
sanctioned way to recognise an ARN in any partition.
|
||||
Reference in new issue
Block a user