fix(servicequotas): curate real AWS VPC quota codes (#4997)

ServiceQuotas only curated codebuild, lambda and organizations; every
other service code got three CRC-synthetic quotas, so real VPC codes
such as L-FE5A380F answered NoSuchResourceException from
GetServiceQuota and GetAWSDefaultServiceQuota. Terraform's
aws_servicequotas_service_quota reads exactly these codes before
requesting an increase.

Add a curated "vpc" entry, plus its service name:
- L-FE5A380F "NAT gateways per Availability Zone" = 5
- L-2AEEBF1A "Rules per network ACL" = 20

Values are the AWS defaults rather than the generous GENERIC_QUOTA_VALUE,
following the organizations entry (L-E619E033 = 50): callers compare a
desired value against these defaults to decide whether to request an
increase, so a realistic default keeps them on the path they take
against AWS. The emulator does not enforce either limit. The synthetic
quotas are still appended.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-10-02 23:49:20 -04:00
1 parent 8e98c087fd
commit 0260a42549
4 files changed
+71 -2

No files matched your search

+3 -1
View File
@@ -11,7 +11,9 @@ them — CodeBuild's `L-2DC20C30` ("Concurrently running builds") and Lambda's `
values are deliberately generous so local pipelines that gate on quota headroom, such
as AWS Landing Zone Accelerator, never stall on a limit the emulator does not enforce. The
Organizations `Maximum number of accounts` quota uses AWS quota code `L-E619E033` and a local value
of 50.
of 50. VPC's `L-FE5A380F` ("NAT gateways per Availability Zone", 5) and `L-2AEEBF1A` ("Rules per
network ACL", 20) carry their AWS default values, so tooling that compares a desired value against
the default before requesting an increase takes the same path it would against AWS.
Applied quotas and AWS default quotas return the same data, and quota values are static.
`RequestServiceQuotaIncrease` is accepted and validated but does not change any quota value —
@@ -49,6 +49,7 @@ public class ServiceQuotasService {
Map.entry("sns", "Amazon Simple Notification Service (Amazon SNS)"),
Map.entry("sqs", "Amazon Simple Queue Service (Amazon SQS)"),
Map.entry("ec2", "Amazon Elastic Compute Cloud (Amazon EC2)"),
Map.entry("vpc", "Amazon Virtual Private Cloud (Amazon VPC)"),
Map.entry("dynamodb", "Amazon DynamoDB"),
Map.entry("logs", "Amazon CloudWatch Logs"),
Map.entry("events", "Amazon EventBridge (CloudWatch Events)"));
@@ -59,7 +60,12 @@ public class ServiceQuotasService {
"lambda", List.of(
new QuotaDefinition("L-B99A9384", "Concurrent executions", GENERIC_QUOTA_VALUE, false)),
"organizations", List.of(
new QuotaDefinition("L-E619E033", "Maximum number of accounts", 50.0, true)));
new QuotaDefinition("L-E619E033", "Maximum number of accounts", 50.0, true)),
// AWS default values: tooling such as Terraform's aws_servicequotas_service_quota
// compares its desired value against these before requesting an increase.
"vpc", List.of(
new QuotaDefinition("L-FE5A380F", "NAT gateways per Availability Zone", 5.0, false),
new QuotaDefinition("L-2AEEBF1A", "Rules per network ACL", 20.0, false)));
private static final List<String> GENERIC_QUOTA_NAMES = List.of(
"Resources per Region",
@@ -175,6 +175,37 @@ class ServiceQuotasIntegrationTest {
.body("Quota.GlobalQuota", equalTo(true));
}
@Test
void vpcQuotasUseAwsQuotaCodesAsDefaultAndApplied() {
for (String target : new String[] {"GetAWSDefaultServiceQuota", "GetServiceQuota"}) {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "ServiceQuotasV20190624." + target)
.header("Authorization", AUTH_HEADER)
.body("{\"ServiceCode\":\"vpc\",\"QuotaCode\":\"L-FE5A380F\"}")
.when()
.post("/")
.then()
.statusCode(200)
.body("Quota.QuotaCode", equalTo("L-FE5A380F"))
.body("Quota.QuotaName", equalTo("NAT gateways per Availability Zone"))
.body("Quota.Value", equalTo(5.0f));
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "ServiceQuotasV20190624." + target)
.header("Authorization", AUTH_HEADER)
.body("{\"ServiceCode\":\"vpc\",\"QuotaCode\":\"L-2AEEBF1A\"}")
.when()
.post("/")
.then()
.statusCode(200)
.body("Quota.QuotaCode", equalTo("L-2AEEBF1A"))
.body("Quota.QuotaName", equalTo("Rules per network ACL"))
.body("Quota.Value", equalTo(20.0f));
}
}
@Test
void listRequestedQuotaHistoryByQuotaReturnsEmptyHistoryForKnownQuota() {
given()
@@ -1,11 +1,14 @@
package io.github.hectorvent.floci.services.servicequotas;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -42,6 +45,33 @@ class ServiceQuotasServiceTest {
assertTrue(codes.contains("L-2DC20C30"), codes.toString());
}
@Test
void vpcResolvesRealQuotaCodesWithNamesThroughGetAndList() {
Map<String, String> want = Map.of(
"L-FE5A380F", "NAT gateways per Availability Zone",
"L-2AEEBF1A", "Rules per network ACL");
Map<String, Double> defaults = Map.of("L-FE5A380F", 5.0, "L-2AEEBF1A", 20.0);
for (Map.Entry<String, String> e : want.entrySet()) {
JsonNode quota = service.getServiceQuota("vpc", e.getKey(), "us-east-1", "000000000000").path("Quota");
assertEquals(e.getKey(), quota.path("QuotaCode").asText());
assertEquals(e.getValue(), quota.path("QuotaName").asText());
assertEquals(defaults.get(e.getKey()), quota.path("Value").asDouble());
assertEquals("Amazon Virtual Private Cloud (Amazon VPC)", quota.path("ServiceName").asText());
}
Map<String, String> listed = new HashMap<>();
service.listServiceQuotas("vpc", null, null, 100, "us-east-1", "000000000000").withArray("Quotas")
.forEach(q -> listed.put(q.path("QuotaCode").asText(), q.path("QuotaName").asText()));
want.forEach((code, name) -> assertEquals(name, listed.get(code), listed.toString()));
assertEquals(want.size() + 3, listed.size(), "synthetic quotas still appended: " + listed);
}
@Test
void vpcUnknownQuotaCodeStillThrowsNoSuchResource() {
AwsException e = assertThrows(AwsException.class,
() -> service.getServiceQuota("vpc", "L-DOESNOTEX", "us-east-1", "000000000000"));
assertEquals("NoSuchResourceException", e.getErrorCode());
}
@Test
void getServiceQuota_unknownCode_throwsNoSuchResource() {
AwsException e = assertThrows(AwsException.class,