Light, fluffy, and always free - The AWS Local Emulator alternative
fix(servicequotas): curate real AWS VPC quota codes (#4997)
Allen Sanborn0260a425496a
diff --git a/docs/services/servicequotas.md b/docs/services/servicequotas.mdindex 1fda386629..12d2c6dd2f 100644--- a/docs/services/servicequotas.md+++ b/docs/services/servicequotas.md@@ -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, suchas AWS Landing Zone Accelerator, never stall on a limit the emulator does not enforce. TheOrganizations `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 —diff --git a/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasService.java b/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasService.javaindex b6727694fa..1384205809 100644--- a/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasService.java+++ b/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasService.java@@ -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",diff --git a/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasIntegrationTest.javaindex 0bc975edf8..303f1d1937 100644--- a/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasIntegrationTest.java@@ -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));+ }+ }+@Testvoid listRequestedQuotaHistoryByQuotaReturnsEmptyHistoryForKnownQuota() {given()diff --git a/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasServiceTest.javaindex 80d9dccee7..f1b31d84b9 100644--- a/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasServiceTest.java@@ -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());+ }+@Testvoid getServiceQuota_unknownCode_throwsNoSuchResource() {AwsException e = assertThrows(AwsException.class,