fix(ec2): honor DHCP options dry runs and restore default set (#6448)

This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-10-25 09:15:34 -04:00
1 parent ddb94d6c15
commit 4244e64833
5 files changed
+191 -10

No files matched your search

@@ -1701,6 +1701,7 @@ public class Ec2QueryHandler {
configurations.add(new DhcpConfiguration(key, values));
}
List<Tag> tags = parseTagsForResource(p, "dhcp-options");
checkDryRun(p);
DhcpOptions options = service.createDhcpOptions(region, configurations);
try {
applyResourceTags(tags, region, options.getDhcpOptionsId());
@@ -1763,11 +1764,13 @@ public class Ec2QueryHandler {
}
private Response handleAssociateDhcpOptions(MultivaluedMap<String, String> p, String region) {
checkDryRun(p);
service.associateDhcpOptions(region, p.getFirst("DhcpOptionsId"), p.getFirst("VpcId"));
return booleanResponse("AssociateDhcpOptions");
}
private Response handleDeleteDhcpOptions(MultivaluedMap<String, String> p, String region) {
checkDryRun(p);
service.deleteDhcpOptions(region, p.getFirst("DhcpOptionsId"));
return booleanResponse("DeleteDhcpOptions");
}
@@ -1409,12 +1409,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
}
}
public void ensureDefaultResources(String region) {
String ownerAccountId = callerAccountId();
String seedScope = ownerAccountId + "::" + region;
if (!seededAccountRegions.add(seedScope)) {
return;
}
private void ensureDefaultDhcpOptions(String region, String ownerAccountId) {
String defaultOptionsId = "dopt-default";
if (dhcpOptions.get(key(region, defaultOptionsId)).isEmpty()) {
DhcpOptions defaultOptions = new DhcpOptions();
@@ -1427,11 +1422,24 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
new DhcpConfiguration("ipv6-address-preferred-lease-time", List.of("140"))));
dhcpOptions.put(key(region, defaultOptionsId), defaultOptions);
}
// Already provisioned in a previous run and reloaded from persistent storage: the default
// VPC (and everything else) is present, so don't re-seed and create duplicates (#1297).
if (!vpcs.scan(k -> k.startsWith(region + "::")).isEmpty()) {
}
public void ensureDefaultResources(String region) {
String ownerAccountId = callerAccountId();
String seedScope = ownerAccountId + "::" + region;
if (!seededAccountRegions.add(seedScope)) {
return;
}
List<Vpc> existingVpcs = vpcs.scan(k -> k.startsWith(region + "::"));
// Already provisioned in a previous run and reloaded from persistent storage: the default
// VPC (and everything else) is present, so don't re-seed and create duplicates (#1297).
if (!existingVpcs.isEmpty()) {
if (existingVpcs.stream().anyMatch(vpc -> "dopt-default".equals(vpc.getDhcpOptionsId()))) {
ensureDefaultDhcpOptions(region, ownerAccountId);
}
return;
}
ensureDefaultDhcpOptions(region, ownerAccountId);
LOG.debugv("Seeding default EC2 resources for region {0}", region);
// Default VPC
@@ -6094,6 +6102,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
rejectOutOfRangePrefix(cidrBlock, "InvalidVpc.Range");
rejectReservedVpcRange(cidrBlock);
ensureDefaultResources(region);
ensureDefaultDhcpOptions(region, callerAccountId());
String vpcId = "vpc-" + randomHex(8);
Vpc vpc = new Vpc();
vpc.setVpcId(vpcId);