mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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
This commit is contained in:
1 parent
b65755da3a
commit
7f4f2377c0
3 files changed
+55
-3
No files matched your search
+12
-3
@@ -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);
|
||||
}
|
||||
|
||||
+17
@@ -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);
|
||||
|
||||
+26
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user