fix(ec2): preserve elastic IP pool and border group (#5821)

* fix(ec2): preserve elastic IP pool and border group

* test(ec2): share account-scoped query requests
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-10-17 08:23:47 -04:00
1 parent 5eb4eecf99
commit 5fc58a9a9c
8 files changed
+228 -15

No files matched your search

@@ -4328,7 +4328,7 @@ public class Ec2QueryHandler {
private Response handleAllocateAddress(MultivaluedMap<String, String> p, String region) {
List<Tag> resourceTags = parseTagsForResource(p, "elastic-ip");
Address addr = service.allocateAddress(region);
Address addr = service.allocateAddress(region, p.getFirst("PublicIpv4Pool"), p.getFirst("NetworkBorderGroup"));
applyResourceTags(resourceTags, region, addr.getAllocationId());
XmlBuilder xml = new XmlBuilder()
.start("AllocateAddressResponse", AwsNamespaces.EC2)
@@ -4336,6 +4336,8 @@ public class Ec2QueryHandler {
.elem("publicIp", addr.getPublicIp())
.elem("domain", addr.getDomain())
.elem("allocationId", addr.getAllocationId())
.elem("publicIpv4Pool", addr.getPublicIpv4Pool())
.elem("networkBorderGroup", addr.getNetworkBorderGroup())
.end("AllocateAddressResponse");
return xmlResponse(xml.build());
}
@@ -5948,6 +5950,8 @@ public class Ec2QueryHandler {
.elem("publicIp", addr.getPublicIp())
.elem("allocationId", addr.getAllocationId())
.elem("domain", addr.getDomain())
.elem("publicIpv4Pool", addr.getPublicIpv4Pool())
.elem("networkBorderGroup", addr.getNetworkBorderGroup())
.elem("instanceId", addr.getInstanceId())
.elem("associationId", addr.getAssociationId())
.elem("networkInterfaceId", addr.getNetworkInterfaceId())
@@ -9785,6 +9785,10 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
// ─── Elastic IPs ───────────────────────────────────────────────────────────
public Address allocateAddress(String region) {
return allocateAddress(region, null, null);
}
public Address allocateAddress(String region, String publicIpv4Pool, String networkBorderGroup) {
ensureDefaultResources(region);
String allocId = "eipalloc-" + randomHex(17);
String ip = "54." + (new Random().nextInt(256)) + "." + (new Random().nextInt(256)) + "." + (new Random().nextInt(256));
@@ -9792,6 +9796,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
addr.setAllocationId(allocId);
addr.setPublicIp(ip);
addr.setRegion(region);
// shortcut: pool and border group are metadata until real pool allocation is modeled.
addr.setPublicIpv4Pool(publicIpv4Pool);
addr.setNetworkBorderGroup(networkBorderGroup);
addresses.put(key(region, allocId), addr);
return addr;
}
@@ -10592,14 +10599,14 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
};
}
// These are the AWS-documented DescribeAddresses filters this store can back with
// real data; two documented filters (network-border-group,
// network-interface-owner-id) are omitted because Address has no such field and
// real data; network-interface-owner-id is omitted because Address has no such field and
// fabricating one would be its own wrong answer.
if (resource instanceof Address addr) {
return switch (filterName) {
case "allocation-id" -> matchesValue(values, addr.getAllocationId());
case "public-ip" -> matchesValue(values, addr.getPublicIp());
case "domain" -> matchesValue(values, addr.getDomain());
case "network-border-group" -> matchesValue(values, addr.getNetworkBorderGroup());
case "association-id" -> addr.getAssociationId() != null
&& matchesValue(values, addr.getAssociationId());
case "instance-id" -> addr.getInstanceId() != null
@@ -13,6 +13,8 @@ public class Address {
private String allocationId;
private String publicIp;
private String domain = "vpc";
private String publicIpv4Pool;
private String networkBorderGroup;
private String instanceId;
private String associationId;
private String networkInterfaceId;
@@ -36,6 +38,13 @@ public class Address {
public String getDomain() { return domain; }
public void setDomain(String domain) { this.domain = domain; }
// Older persisted allocations used the regional Amazon pool without recording its metadata.
public String getPublicIpv4Pool() { return publicIpv4Pool != null ? publicIpv4Pool : "amazon"; }
public void setPublicIpv4Pool(String publicIpv4Pool) { this.publicIpv4Pool = publicIpv4Pool; }
public String getNetworkBorderGroup() { return networkBorderGroup != null ? networkBorderGroup : region; }
public void setNetworkBorderGroup(String networkBorderGroup) { this.networkBorderGroup = networkBorderGroup; }
public String getInstanceId() { return instanceId; }
public void setInstanceId(String instanceId) { this.instanceId = instanceId; }