fix: preserve Route 53 private hosted-zone VPC associations (#2342)

* fix: preserve Route 53 private hosted-zone VPC associations

Fixes #2294

* fix(route53): correct SDK accessor, validate VPC, dedupe test order

Addresses @pgermosen's three review points:

1. sdk-test-java failed to compile: the real SDK accessor for the VPCs list is
   vpCs(), not vpcs(). Confirmed with javap against the pinned
   route53-2.44.14.jar.

2. parseVpcAssociation accepted a <VPC> element carrying only one of VPCId /
   VPCRegion and still marked the zone private with a half-populated
   association. AWS requires both together whenever VPC is present, so an
   incomplete element is now rejected with InvalidInput/400.

3. Route53IntegrationTest had two methods at @Order(3), leaving their relative
   order undefined. Renumbered the trailing cases so every order is unique.

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
This commit is contained in:
Matt Van HornandMatt Van Horn authored and GitHub committed 2026-08-20 23:28:14 -04:00
1 parent c4597f2e53
commit 967ea843a0
6 files changed
+232 -28

No files matched your search

@@ -0,0 +1,69 @@
package com.floci.test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.route53.Route53Client;
import software.amazon.awssdk.services.route53.model.CreateHostedZoneRequest;
import software.amazon.awssdk.services.route53.model.CreateHostedZoneResponse;
import software.amazon.awssdk.services.route53.model.DeleteHostedZoneRequest;
import software.amazon.awssdk.services.route53.model.GetHostedZoneRequest;
import software.amazon.awssdk.services.route53.model.GetHostedZoneResponse;
import software.amazon.awssdk.services.route53.model.VPC;
import software.amazon.awssdk.services.route53.model.VPCRegion;
import static org.assertj.core.api.Assertions.assertThat;
@DisplayName("Route 53")
class Route53Test {
private static Route53Client route53;
@BeforeAll
static void setup() {
route53 = TestFixtures.route53Client();
}
@AfterAll
static void cleanup() {
if (route53 != null) {
route53.close();
}
}
@Test
void createAndGetPrivateHostedZonePreservesVpcAssociation() {
VPC vpc = VPC.builder()
.vpcId("vpc-sdk-private")
.vpcRegion(VPCRegion.US_WEST_2)
.build();
String zoneId = null;
try {
CreateHostedZoneResponse created = route53.createHostedZone(CreateHostedZoneRequest.builder()
.name(TestFixtures.uniqueName("private-zone") + ".example.com")
.callerReference(TestFixtures.uniqueName("private-zone-ref"))
.vpc(vpc)
.build());
zoneId = created.hostedZone().id();
assertThat(created.hostedZone().config().privateZone()).isTrue();
assertThat(created.vpc().vpcId()).isEqualTo(vpc.vpcId());
assertThat(created.vpc().vpcRegion()).isEqualTo(vpc.vpcRegion());
GetHostedZoneResponse fetched = route53.getHostedZone(
GetHostedZoneRequest.builder().id(zoneId).build());
assertThat(fetched.hostedZone().config().privateZone()).isTrue();
assertThat(fetched.vpCs()).singleElement().satisfies(association -> {
assertThat(association.vpcId()).isEqualTo(vpc.vpcId());
assertThat(association.vpcRegion()).isEqualTo(vpc.vpcRegion());
});
} finally {
if (zoneId != null) {
route53.deleteHostedZone(DeleteHostedZoneRequest.builder().id(zoneId).build());
}
}
}
}