From 7f4f2377c09d68751088a2c468adc8ddd86e3b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Javier=20Bar=C3=B3n?= Date: Mon, 2 Nov 2026 13:40:40 +0100 Subject: [PATCH] fix(controltower): accept the landing zone id as landingZoneIdentifier (#7298) The AWS Terraform provider stores the landing zone id (the last ARN segment) and sends it on read, update and delete. Floci only matched the full ARN, so every apply failed after a successful create. Closes #7295 --- .../controltower/ControlTowerService.java | 15 ++++++++--- ...ControlTowerControllerIntegrationTest.java | 17 ++++++++++++ .../controltower/ControlTowerServiceTest.java | 26 +++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/controltower/ControlTowerService.java b/src/main/java/io/github/hectorvent/floci/services/controltower/ControlTowerService.java index b680abc48c..29f6b79d27 100644 --- a/src/main/java/io/github/hectorvent/floci/services/controltower/ControlTowerService.java +++ b/src/main/java/io/github/hectorvent/floci/services/controltower/ControlTowerService.java @@ -159,13 +159,22 @@ public class ControlTowerService { ? getOrSeedLandingZone(accountId, region) : landingZoneStore.get(region).orElseThrow(() -> new AwsException("ResourceNotFoundException", "Landing zone not found: " + landingZoneIdentifier, 404)); - if (!landingZone.getArn().equals(landingZoneIdentifier)) { + if (!matchesIdentifier(landingZone, landingZoneIdentifier)) { throw new AwsException("ResourceNotFoundException", "Landing zone not found: " + landingZoneIdentifier, 404); } return landingZone; } + /** + * Matches the full ARN or the landing zone id (the last ARN segment). The AWS Terraform + * provider stores the id and sends it as landingZoneIdentifier on read, update and delete. + */ + private static boolean matchesIdentifier(LandingZone landingZone, String landingZoneIdentifier) { + String arn = landingZone.getArn(); + return arn.equals(landingZoneIdentifier) || arn.endsWith("/" + landingZoneIdentifier); + } + public synchronized CreateLandingZoneResult createLandingZone( String accountId, String region, JsonNode request) { requireObject(request, "Request body"); @@ -227,7 +236,7 @@ public class ControlTowerService { LandingZone landingZone = landingZoneStore.get(region) .orElseThrow(() -> new AwsException("ResourceNotFoundException", "Landing zone not found: " + landingZoneIdentifier, 404)); - if (!landingZone.getArn().equals(landingZoneIdentifier)) { + if (!matchesIdentifier(landingZone, landingZoneIdentifier)) { throw new AwsException("ResourceNotFoundException", "Landing zone not found: " + landingZoneIdentifier, 404); } @@ -244,7 +253,7 @@ public class ControlTowerService { LandingZone landingZone = landingZoneStore.get(region) .orElseThrow(() -> new AwsException("ResourceNotFoundException", "Landing zone not found: " + landingZoneIdentifier, 404)); - if (!landingZone.getArn().equals(landingZoneIdentifier)) { + if (!matchesIdentifier(landingZone, landingZoneIdentifier)) { throw new AwsException("ResourceNotFoundException", "Landing zone not found: " + landingZoneIdentifier, 404); } diff --git a/src/test/java/io/github/hectorvent/floci/services/controltower/ControlTowerControllerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/controltower/ControlTowerControllerIntegrationTest.java index 7cd889f95f..bc89e906c5 100644 --- a/src/test/java/io/github/hectorvent/floci/services/controltower/ControlTowerControllerIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/controltower/ControlTowerControllerIntegrationTest.java @@ -72,6 +72,23 @@ class ControlTowerControllerIntegrationTest { .body("operationIdentifier", containsString("-")); } + @Test + void getLandingZoneAcceptsLandingZoneIdLikeTheTerraformProvider() { + String authorization = auth("000000000250", EAST); + String arn = listLandingZonesArn(authorization); + String id = arn.substring(arn.lastIndexOf('/') + 1); + + given() + .contentType("application/json") + .header("Authorization", authorization) + .body("{\"landingZoneIdentifier\":\"" + id + "\"}") + .when() + .post("/get-landingzone") + .then() + .statusCode(200) + .body("landingZone.arn", equalTo(arn)); + } + @Test void getLandingZoneReturnsEveryFieldLzaNonNullAsserts() { String authorization = auth("000000000202", EAST); diff --git a/src/test/java/io/github/hectorvent/floci/services/controltower/ControlTowerServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/controltower/ControlTowerServiceTest.java index fbb894688e..0da0d14b8c 100644 --- a/src/test/java/io/github/hectorvent/floci/services/controltower/ControlTowerServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/controltower/ControlTowerServiceTest.java @@ -157,6 +157,32 @@ class ControlTowerServiceTest { assertEquals(404, unknown.getHttpStatus()); } + @Test + void getLandingZoneAcceptsLandingZoneIdAsIdentifier() throws Exception { + LandingZone landingZone = service.getLandingZone(ACCOUNT, REGION, + objectMapper.readTree("{\"landingZoneIdentifier\":\"FLOCISEEDEDLZ1\"}")); + + assertEquals(SEEDED_ARN, landingZone.getArn()); + } + + @Test + void getLandingZoneRejectsUnknownLandingZoneId() { + AwsException unknown = assertThrows(AwsException.class, + () -> service.getLandingZone(ACCOUNT, REGION, + objectMapper.readTree("{\"landingZoneIdentifier\":\"other\"}"))); + assertEquals("ResourceNotFoundException", unknown.getErrorCode()); + } + + @Test + void deleteLandingZoneAcceptsLandingZoneIdAsIdentifier() throws Exception { + service.getOrSeedLandingZone(ACCOUNT, REGION); + + String opId = service.deleteLandingZone(ACCOUNT, REGION, + objectMapper.readTree("{\"landingZoneIdentifier\":\"FLOCISEEDEDLZ1\"}")); + + assertEquals("DELETE", service.getOperationType(ACCOUNT, REGION, opId)); + } + @Test void getLandingZoneReturnsSeededLandingZoneForMatchingIdentifier() throws Exception { LandingZone landingZone = service.getLandingZone(ACCOUNT, REGION,