Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(ec2): preserve endpoint IP types across updates and templates (#5438)

David Phillips80e8b7465d72
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2Tests.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2Tests.java
index 0ceb22d095..913c63fb54 100644
--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2Tests.java
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2Tests.java
@@ -1043,6 +1043,12 @@ class Ec2Tests {
VpcEndpoint ep = described.vpcEndpoints().get(0);
assertThat(ep.ipAddressType()).isEqualTo(IpAddressType.IPV4);
assertThat(ep.stateAsString()).isEqualTo("available");
+ ec2.modifyVpcEndpoint(ModifyVpcEndpointRequest.builder().vpcEndpointId(endpointId)
+ .ipAddressType(IpAddressType.DUALSTACK).build());
+ assertThat(ec2.describeVpcEndpoints(DescribeVpcEndpointsRequest.builder()
+ .vpcEndpointIds(endpointId).build()).vpcEndpoints().get(0).ipAddressType())
+ .isEqualTo(IpAddressType.DUALSTACK);
+
assertThat(ep.networkInterfaceIds())
.as("DescribeVpcEndpoints response")
diff --git a/docs/services/ec2.md b/docs/services/ec2.md
index e11a8a9de5..0f4a78d3d3 100644
--- a/docs/services/ec2.md
+++ b/docs/services/ec2.md
@@ -112,6 +112,8 @@ Notes and limitations:
EC2 containers receive `AWS_EC2_METADATA_SERVICE_ENDPOINT` for IMDS and `AWS_ENDPOINT_URL` for AWS service API calls back to Floci.
+CloudFormation `AWS::EC2::VPCEndpoint` resolves `IpAddressType` on create and update, including parameter references. Omission, a selected `AWS::NoValue` branch, or `not-specified` uses the default `ipv4`; an explicitly empty value is rejected. Updates retain the existing replacement behavior; synthetic interfaces remain IPv4-only.
+
## Instance Metadata Service (IMDS)
Floci runs an IMDS-compatible HTTP server on port `9169` of the host. Each launched container receives the environment variable `AWS_EC2_METADATA_SERVICE_ENDPOINT` pointing to this server.
@@ -226,7 +228,7 @@ Floci seeds the following resources on first use in each region so Terraform, th
| DescribeVpcEndpointServices | Lists common AWS interface endpoint services and S3 (gateway and interface) in every availability zone, named per partition (see [Partitions](../configuration/partitions.md)). A `ServiceName` filter is echoed back as asked. |
| CreateVpcEndpoint | Creates a VPC endpoint record, including its `PolicyDocument` and the per-subnet IPv4 and IPv6 addresses named by `SubnetConfiguration.N`. `IpAddressType` defaults to `ipv4`. Interface and gateway address types are stored as metadata. Synthesized endpoint interfaces still carry IPv4 only; IPv6 networking is not emulated. An `Ipv4` value outside the named subnet's CIDR, or among the first four or the last address AWS reserves in it, is rejected with `InvalidParameterValue`. |
| DescribeVpcEndpoints | Lists or returns stored VPC endpoints, including their IP address type. |
-| ModifyVpcEndpoint | Associates or disassociates route tables, subnets and security groups, and sets or resets the endpoint policy. `SubnetConfiguration.N` replaces the addresses pinned for a subnet, under the same address validation as CreateVpcEndpoint. `DnsOptions` and `IpAddressType` are accepted and ignored. |
+| ModifyVpcEndpoint | Associates or disassociates route tables, subnets and security groups, sets or resets the endpoint policy, and updates stored `IpAddressType` metadata. Omitting the type preserves its current value; malformed types are rejected before changes are applied. `SubnetConfiguration.N` replaces the addresses pinned for a subnet, under the same address validation as CreateVpcEndpoint. `DnsOptions` is accepted and ignored. |
| DeleteVpcEndpoints | Deletes VPC endpoint records. |
| DescribeVpnGateways | Validates filters and returns empty discovery results; explicit IDs return not-found errors. |
| DescribeEgressOnlyInternetGateways | Validates filters and pagination parameters and returns an empty set, including for explicit IDs, as AWS does. |
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisioner.java
index fab7d51e67..c7a6f652c0 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisioner.java
@@ -54,6 +54,12 @@ public class Ec2VpcEndpointCfnProvisioner implements CfnResourceProvisioner {
Boolean privateDnsEnabled = privateDns != null && !privateDns.isBlank()
? Boolean.parseBoolean(privateDns)
: null;
+ JsonNode addressTypeNode = ctx.engine().resolveNodeOmittingNoValue(props.get("IpAddressType"));
+ String ipAddressType = addressTypeNode == null || addressTypeNode.isNull() || addressTypeNode.isMissingNode()
+ ? null : addressTypeNode.asText();
+ if ("not-specified".equals(ipAddressType)) {
+ ipAddressType = null;
+ }
String previousEndpointId = r.getPhysicalId();
VpcEndpoint endpoint = ec2Service.createVpcEndpoint(ctx.region(), vpcId, serviceName,
endpointType != null ? endpointType : "Gateway",
@@ -62,7 +68,7 @@ public class Ec2VpcEndpointCfnProvisioner implements CfnResourceProvisioner {
resolveIdList(props, "SecurityGroupIds", ctx),
privateDnsEnabled,
policyDocument(props, ctx),
- List.of());
+ List.of(), List.of(), ipAddressType);
r.setPhysicalId(endpoint.getVpcEndpointId());
r.getAttributes().put("Id", endpoint.getVpcEndpointId());
// An unset attribute resolves to the literal "LogicalId.CreationTimestamp" rather than
diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java
index b3f0a00ff0..994bc91c34 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java
@@ -2212,7 +2212,7 @@ public class Ec2QueryHandler {
p.getFirst("PolicyDocument"),
p.getFirst("ResetPolicy") != null ? Boolean.valueOf(p.getFirst("ResetPolicy")) : null,
p.getFirst("PrivateDnsEnabled") != null ? Boolean.valueOf(p.getFirst("PrivateDnsEnabled")) : null,
- parseSubnetConfigurations(p));
+ parseSubnetConfigurations(p), p.getFirst("IpAddressType"));
// ModifyVpcEndpoint returns only a boolean; the caller re-reads the endpoint
// through DescribeVpcEndpoints to see the result.
XmlBuilder xml = new XmlBuilder()
diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java
index 0749dc23a9..bd1cbcda9e 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java
@@ -4876,10 +4876,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
List<String> securityGroupIds, Boolean privateDnsEnabled,
String policyDocument, List<Tag> endpointTags,
List<VpcEndpointSubnetConfiguration> subnetConfigurations, String ipAddressType) {
- if (ipAddressType != null && !Set.of("ipv4", "ipv6", "dualstack").contains(ipAddressType)) {
- throw new AwsException("InvalidParameterValue",
- "IpAddressType must be ipv4, ipv6, or dualstack.", 400);
- }
+ validateVpcEndpointIpAddressType(ipAddressType);
ensureDefaultResources(region);
getRequiredVpc(region, vpcId);
for (String routeTableId : routeTableIds) {
@@ -4929,6 +4926,13 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
return endpoint;
}
+ private static void validateVpcEndpointIpAddressType(String ipAddressType) {
+ if (ipAddressType != null && !Set.of("ipv4", "ipv6", "dualstack").contains(ipAddressType)) {
+ throw new AwsException("InvalidParameterValue",
+ "IpAddressType must be ipv4, ipv6, or dualstack.", 400);
+ }
+ }
+
/**
* Applies a ModifyVpcEndpoint request. Every parameter is optional and each applies
* independently, so one request may move route tables and rewrite the policy.
@@ -4954,6 +4958,17 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
List<String> addSecurityGroupIds, List<String> removeSecurityGroupIds,
String policyDocument, Boolean resetPolicy, Boolean privateDnsEnabled,
List<VpcEndpointSubnetConfiguration> subnetConfigurations) {
+ return modifyVpcEndpoint(region, endpointId, addRouteTableIds, removeRouteTableIds,
+ addSubnetIds, removeSubnetIds, addSecurityGroupIds, removeSecurityGroupIds,
+ policyDocument, resetPolicy, privateDnsEnabled, subnetConfigurations, null);
+ }
+
+ public VpcEndpoint modifyVpcEndpoint(String region, String endpointId,
+ List<String> addRouteTableIds, List<String> removeRouteTableIds,
+ List<String> addSubnetIds, List<String> removeSubnetIds,
+ List<String> addSecurityGroupIds, List<String> removeSecurityGroupIds,
+ String policyDocument, Boolean resetPolicy, Boolean privateDnsEnabled,
+ List<VpcEndpointSubnetConfiguration> subnetConfigurations, String ipAddressType) {
// VpcEndpointId is the one required member of ModifyVpcEndpointRequest. The model
// requires it to be present, not to be non-empty, so only an absent value is a
// MissingParameter; a present-but-unknown id is an InvalidVpcEndpointId.NotFound.
@@ -4961,6 +4976,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
throw new AwsException("MissingParameter",
"The request must contain the parameter VpcEndpointId", 400);
}
+ validateVpcEndpointIpAddressType(ipAddressType);
ensureDefaultResources(region);
// Terraform declares each aws_vpc_endpoint_route_table_association as its own
// resource and applies them in parallel, so several ModifyVpcEndpoint calls land
@@ -4972,7 +4988,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
return modifyVpcEndpointLocked(region, endpointId,
addRouteTableIds, removeRouteTableIds, addSubnetIds, removeSubnetIds,
addSecurityGroupIds, removeSecurityGroupIds,
- policyDocument, resetPolicy, privateDnsEnabled, subnetConfigurations);
+ policyDocument, resetPolicy, privateDnsEnabled, subnetConfigurations, ipAddressType);
}
}
@@ -4982,7 +4998,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
List<String> addSecurityGroupIds, List<String> removeSecurityGroupIds,
String policyDocument, Boolean resetPolicy,
Boolean privateDnsEnabled,
- List<VpcEndpointSubnetConfiguration> subnetConfigurations) {
+ List<VpcEndpointSubnetConfiguration> subnetConfigurations,
+ String ipAddressType) {
VpcEndpoint endpoint = getRequiredVpcEndpoint(region, endpointId);
// Validate every referenced id before mutating anything, so a request naming one
@@ -5003,6 +5020,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
applyIdChanges(endpoint.getSecurityGroupIds(), addSecurityGroupIds, removeSecurityGroupIds);
applySubnetConfigurations(endpoint, subnetConfigurations, removeSubnetIds);
+ if (ipAddressType != null) {
+ endpoint.setIpAddressType(ipAddressType);
+ }
if (Boolean.TRUE.equals(resetPolicy)) {
endpoint.setPolicyDocument(null);
} else if (policyDocument != null) {
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcEndpointIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcEndpointIntegrationTest.java
index d2df24a6f1..c55bcc4060 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcEndpointIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcEndpointIntegrationTest.java
@@ -3,6 +3,8 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
@@ -24,6 +26,101 @@ class CloudFormationVpcEndpointIntegrationTest {
private static final String EC2_AUTH =
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/ec2/aws4_request";
+ @Test
+ void addressTypeResolvesParameterOnCreateAndUpdate() {
+ String stack = "cfn-vpce-ip-" + Long.toString(System.nanoTime(), 36);
+ String vpc = XmlParser.extractFirst(given().header("Authorization", EC2_AUTH)
+ .formParam("Action", "CreateVpc").formParam("CidrBlock", "10.63.0.0/16")
+ .post("/").then().statusCode(200).extract().asString(), "vpcId", null);
+ String template = """
+ {"Parameters":{"AddressType":{"Type":"String"}},"Resources":{
+ "Endpoint":{"Type":"AWS::EC2::VPCEndpoint","Properties":{
+ "VpcId":"%s","ServiceName":"com.amazonaws.us-east-1.s3",
+ "IpAddressType":{"Ref":"AddressType"}}}},
+ "Outputs":{"EndpointId":{"Value":{"Ref":"Endpoint"}}}}
+ """.formatted(vpc);
+ try {
+ String action = "CreateStack";
+ for (String type : new String[]{"ipv6", "dualstack", "not-specified"}) {
+ given().header("Authorization", CFN_AUTH).formParam("Action", action)
+ .formParam("StackName", stack).formParam("TemplateBody", template)
+ .formParam("Parameters.member.1.ParameterKey", "AddressType")
+ .formParam("Parameters.member.1.ParameterValue", type)
+ .post("/").then().statusCode(200);
+ assertEquals("CreateStack".equals(action) ? "CREATE_COMPLETE" : "UPDATE_COMPLETE",
+ CfnStackWaits.awaitTerminal(stack, CFN_AUTH).status());
+ String described = given().header("Authorization", CFN_AUTH)
+ .formParam("Action", "DescribeStacks").formParam("StackName", stack)
+ .post("/").then().statusCode(200).extract().asString();
+ String id = XmlParser.extractFirst(described, "OutputValue", null);
+ String endpoint = given().header("Authorization", EC2_AUTH)
+ .formParam("Action", "DescribeVpcEndpoints").formParam("VpcEndpointId.1", id)
+ .post("/").then().statusCode(200).extract().asString();
+ assertEquals("not-specified".equals(type) ? "ipv4" : type,
+ XmlParser.extractFirst(endpoint, "ipAddressType", null));
+ action = "UpdateStack";
+ }
+ } finally {
+ given().header("Authorization", CFN_AUTH).formParam("Action", "DeleteStack")
+ .formParam("StackName", stack).post("/").then().statusCode(200);
+ CfnStackWaits.awaitStackDeleted(stack, CFN_AUTH);
+ given().header("Authorization", EC2_AUTH).formParam("Action", "DeleteVpc")
+ .formParam("VpcId", vpc).post("/").then().statusCode(200);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"omit", "dualstack", ""})
+ void conditionalAddressTypeOmitsOnlyNoValue(String initialType) {
+ String stack = "cfn-vpce-conditional-ip-" + Long.toString(System.nanoTime(), 36);
+ String vpc = XmlParser.extractFirst(given().header("Authorization", EC2_AUTH)
+ .formParam("Action", "CreateVpc").formParam("CidrBlock", "10.64.0.0/16")
+ .post("/").then().statusCode(200).extract().asString(), "vpcId", null);
+ String template = """
+ {"Parameters":{"AddressType":{"Type":"String"}},
+ "Conditions":{"UseType":{"Fn::Not":[{"Fn::Equals":[{"Ref":"AddressType"},"omit"]}]}},
+ "Resources":{
+ "Endpoint":{"Type":"AWS::EC2::VPCEndpoint","Properties":{
+ "VpcId":"%s","ServiceName":"com.amazonaws.us-east-1.s3",
+ "IpAddressType":{"Fn::If":["UseType",{"Ref":"AddressType"},{"Ref":"AWS::NoValue"}]}}}},
+ "Outputs":{"EndpointId":{"Value":{"Ref":"Endpoint"}}}}
+ """.formatted(vpc);
+ try {
+ String action = "CreateStack";
+ for (String type : new String[]{initialType, "omit".equals(initialType) ? "dualstack" : "omit", initialType}) {
+ given().header("Authorization", CFN_AUTH).formParam("Action", action)
+ .formParam("StackName", stack).formParam("TemplateBody", template)
+ .formParam("Parameters.member.1.ParameterKey", "AddressType")
+ .formParam("Parameters.member.1.ParameterValue", type)
+ .post("/").then().statusCode(200);
+ if (type.isEmpty()) {
+ CfnStackWaits.StackState failed = CfnStackWaits.awaitTerminal(stack, CFN_AUTH);
+ assertEquals("ROLLBACK_COMPLETE", failed.status(), failed.reason());
+ assertTrue(failed.reason().contains("IpAddressType"), failed.reason());
+ break;
+ }
+ assertEquals("CreateStack".equals(action) ? "CREATE_COMPLETE" : "UPDATE_COMPLETE",
+ CfnStackWaits.awaitTerminal(stack, CFN_AUTH).status());
+ String described = given().header("Authorization", CFN_AUTH)
+ .formParam("Action", "DescribeStacks").formParam("StackName", stack)
+ .post("/").then().statusCode(200).extract().asString();
+ String id = XmlParser.extractFirst(described, "OutputValue", null);
+ String endpoint = given().header("Authorization", EC2_AUTH)
+ .formParam("Action", "DescribeVpcEndpoints").formParam("VpcEndpointId.1", id)
+ .post("/").then().statusCode(200).extract().asString();
+ assertEquals("omit".equals(type) ? "ipv4" : type,
+ XmlParser.extractFirst(endpoint, "ipAddressType", null));
+ action = "UpdateStack";
+ }
+ } finally {
+ given().header("Authorization", CFN_AUTH).formParam("Action", "DeleteStack")
+ .formParam("StackName", stack).post("/").then().statusCode(200);
+ CfnStackWaits.awaitStackDeleted(stack, CFN_AUTH);
+ given().header("Authorization", EC2_AUTH).formParam("Action", "DeleteVpc")
+ .formParam("VpcId", vpc).post("/").then().statusCode(200);
+ }
+ }
+
@Test
void createStackProvisionsGatewayEndpointAndDeleteRemovesIt() {
String suffix = Long.toString(System.nanoTime(), 36);
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisionerTest.java
index 3b1ee980b4..45a63d11c9 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisionerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisionerTest.java
@@ -44,6 +44,7 @@ class Ec2VpcEndpointCfnProvisionerTest {
CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class);
when(engine.resolve(any())).thenAnswer(inv -> fakeResolve(inv.getArgument(0)));
when(engine.resolveNode(any())).thenAnswer(inv -> fakeResolveNode(inv.getArgument(0)));
+ when(engine.resolveNodeOmittingNoValue(any())).thenAnswer(inv -> fakeResolveNode(inv.getArgument(0)));
// Same contract as the real resolveJsonAttribute: resolve the tree, then unwrap a
// textual result rather than re-serialising it (#2317's double-encoding trap).
when(engine.resolveJsonAttribute(any())).thenAnswer(inv -> {
@@ -113,7 +114,7 @@ class Ec2VpcEndpointCfnProvisionerTest {
@Test
void gatewayEndpointSetsPhysicalIdAndResolvesRefs() {
when(ec2.createVpcEndpoint(eq("us-east-1"), eq("resolved-Vpc"), eq("com.amazonaws.us-east-1.s3"),
- eq("Gateway"), eq(List.of("resolved-Rt")), eq(List.of()), eq(List.of()), isNull(), isNull(), anyList()))
+ eq("Gateway"), eq(List.of("resolved-Rt")), eq(List.of()), eq(List.of()), isNull(), isNull(), anyList(), anyList(), any()))
.thenReturn(endpoint("vpce-123"));
StackResource r = resource();
ObjectNode props = mapper.createObjectNode()
@@ -132,7 +133,7 @@ class Ec2VpcEndpointCfnProvisionerTest {
@Test
void dnsEntriesPairTheZoneWithTheNameAndJoinOnCommas() {
when(ec2.createVpcEndpoint(anyString(), anyString(), anyString(), anyString(),
- anyList(), anyList(), anyList(), any(), any(), anyList()))
+ anyList(), anyList(), anyList(), any(), any(), anyList(), anyList(), any()))
.thenReturn(endpoint("vpce-entries"));
when(ec2.endpointDnsEntries(any())).thenReturn(List.of(
new VpcEndpointDnsEntry("vpce-entries-ab12cd34.s3.us-east-1.vpce.amazonaws.com", "ZREGIONAL"),
@@ -151,7 +152,7 @@ class Ec2VpcEndpointCfnProvisionerTest {
@Test
void privateDnsEnabledResolvesThroughEngine() {
when(ec2.createVpcEndpoint(anyString(), anyString(), anyString(), anyString(),
- anyList(), anyList(), anyList(), eq(Boolean.TRUE), any(), anyList()))
+ anyList(), anyList(), anyList(), eq(Boolean.TRUE), any(), anyList(), anyList(), any()))
.thenReturn(endpoint("vpce-dns"));
StackResource r = resource();
ObjectNode props = mapper.createObjectNode()
@@ -165,7 +166,7 @@ class Ec2VpcEndpointCfnProvisionerTest {
assertEquals("vpce-dns", r.getPhysicalId());
verify(ec2).createVpcEndpoint(eq("us-east-1"), eq("vpc-1"), eq("com.amazonaws.us-east-1.ecr.api"),
- eq("Interface"), anyList(), anyList(), anyList(), eq(Boolean.TRUE), any(), anyList());
+ eq("Interface"), anyList(), anyList(), anyList(), eq(Boolean.TRUE), any(), anyList(), anyList(), any());
}
@Test
@@ -174,7 +175,7 @@ class Ec2VpcEndpointCfnProvisionerTest {
// Passing null here would drop a CloudFormation-declared policy exactly as the
// EC2 API path used to.
when(ec2.createVpcEndpoint(anyString(), anyString(), anyString(), anyString(),
- anyList(), anyList(), anyList(), any(), any(), anyList()))
+ anyList(), anyList(), anyList(), any(), any(), anyList(), anyList(), any()))
.thenReturn(endpoint("vpce-policy"));
StackResource r = resource();
ObjectNode props = mapper.createObjectNode()
@@ -193,7 +194,7 @@ class Ec2VpcEndpointCfnProvisionerTest {
verify(ec2).createVpcEndpoint(eq("us-east-1"), eq("vpc-1"), eq("com.amazonaws.us-east-1.s3"),
anyString(), anyList(), anyList(), anyList(), any(),
- eq(policy.toString()), anyList());
+ eq(policy.toString()), anyList(), anyList(), any());
}
@Test
@@ -201,7 +202,7 @@ class Ec2VpcEndpointCfnProvisionerTest {
// A PolicyDocument carrying Fn::Sub/Ref must reach Ec2Service resolved, or
// DescribeVpcEndpoints hands the caller back literal template text.
when(ec2.createVpcEndpoint(anyString(), anyString(), anyString(), anyString(),
- anyList(), anyList(), anyList(), any(), any(), anyList()))
+ anyList(), anyList(), anyList(), any(), any(), anyList(), anyList(), any()))
.thenReturn(endpoint("vpce-sub"));
StackResource r = resource();
ObjectNode props = mapper.createObjectNode()
@@ -221,7 +222,7 @@ class Ec2VpcEndpointCfnProvisionerTest {
ArgumentCaptor<String> stored = ArgumentCaptor.forClass(String.class);
verify(ec2).createVpcEndpoint(anyString(), anyString(), anyString(), anyString(),
- anyList(), anyList(), anyList(), any(), stored.capture(), anyList());
+ anyList(), anyList(), anyList(), any(), stored.capture(), anyList(), anyList(), any());
String document = stored.getValue();
assertTrue(document.contains("arn:aws:s3:::us-east-1-artifacts/*"), document);
assertTrue(document.contains("resolved-AppRole"), document);
@@ -232,7 +233,7 @@ class Ec2VpcEndpointCfnProvisionerTest {
@Test
void anAbsentPolicyDocumentStaysNull() {
when(ec2.createVpcEndpoint(anyString(), anyString(), anyString(), anyString(),
- anyList(), anyList(), anyList(), any(), isNull(), anyList()))
+ anyList(), anyList(), anyList(), any(), isNull(), anyList(), anyList(), any()))
.thenReturn(endpoint("vpce-nopolicy"));
StackResource r = resource();
ObjectNode props = mapper.createObjectNode()
@@ -242,13 +243,13 @@ class Ec2VpcEndpointCfnProvisionerTest {
provisioner.provision(r, props, ctx());
verify(ec2).createVpcEndpoint(anyString(), anyString(), anyString(), anyString(),
- anyList(), anyList(), anyList(), any(), isNull(), anyList());
+ anyList(), anyList(), anyList(), any(), isNull(), anyList(), anyList(), any());
}
@Test
void updateReplacesAndDeletesPreviousEndpoint() {
when(ec2.createVpcEndpoint(anyString(), anyString(), anyString(), anyString(),
- anyList(), anyList(), anyList(), any(), any(), anyList()))
+ anyList(), anyList(), anyList(), any(), any(), anyList(), anyList(), any()))
.thenReturn(endpoint("vpce-new"));
StackResource r = resource();
r.setPhysicalId("vpce-old");
diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ModifyVpcEndpointTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ModifyVpcEndpointTest.java
index b6e1d398a4..4dfc59da05 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ModifyVpcEndpointTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ModifyVpcEndpointTest.java
@@ -77,6 +77,38 @@ class Ec2ModifyVpcEndpointTest {
return ec2("DescribeVpcEndpoints", "VpcEndpointId.1", endpointId);
}
+ @ParameterizedTest
+ @ValueSource(strings = {"Gateway", "Interface"})
+ void modifyingAddressTypePersistsAndOmissionPreservesIt(String endpointType) {
+ String vpcId = xmlValue(ec2("CreateVpc", "CidrBlock", "10.81.0.0/16"), "vpcId");
+ String id = xmlValue(ec2("CreateVpcEndpoint", "VpcId", vpcId,
+ "ServiceName", "com.amazonaws.us-east-1.s3", "VpcEndpointType", endpointType), "vpcEndpointId");
+ for (String type : List.of("ipv6", "dualstack", "ipv4")) {
+ ec2("ModifyVpcEndpoint", "VpcEndpointId", id, "IpAddressType", type);
+ assertEquals(type, xmlValue(describe(id), "ipAddressType"));
+ ec2("ModifyVpcEndpoint", "VpcEndpointId", id, "PrivateDnsEnabled", "false");
+ assertEquals(type, xmlValue(describe(id), "ipAddressType"));
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"bogus", "IPv4", "", " ", "not-specified"})
+ void invalidModifiedAddressTypeDoesNotApplyOtherChanges(String ipAddressType) {
+ Fixture f = fixture("10.80.0.0/16");
+ given().header("Authorization", AUTH_HEADER)
+ .formParam("Action", "ModifyVpcEndpoint")
+ .formParam("VpcEndpointId", f.endpointId())
+ .formParam("IpAddressType", ipAddressType)
+ .formParam("AddRouteTableId.1", f.routeTableId())
+ .formParam("PolicyDocument", POLICY)
+ .when().post("/").then().statusCode(400)
+ .body(hasXPath("//*[local-name()='Code']", equalTo("InvalidParameterValue")));
+ VpcEndpoint saved = service.describeVpcEndpoints("us-east-1", List.of(f.endpointId()), Map.of()).getFirst();
+ assertEquals("ipv4", saved.getIpAddressType());
+ assertEquals(List.of(), saved.getRouteTableIds());
+ assertNull(saved.getPolicyDocument());
+ }
+
@Test
void endpointStatesUseAwsWireValues() {
Fixture f = fixture("10.89.0.0/16");