mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(ec2): preserve endpoint IP types across updates and templates (#5438)
* fix(ec2): preserve endpoint IP types across updates and templates * fix(ec2): honor omitted endpoint address types in templates
This commit is contained in:
1 parent
f4bce30269
commit
80e8b7465d
8 files changed
+184
-20
No files matched your search
+7
-1
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user