diff --git a/src/main/java/io/github/hectorvent/floci/services/msk/MskService.java b/src/main/java/io/github/hectorvent/floci/services/msk/MskService.java index f27bd831a7..743ce7f634 100644 --- a/src/main/java/io/github/hectorvent/floci/services/msk/MskService.java +++ b/src/main/java/io/github/hectorvent/floci/services/msk/MskService.java @@ -162,8 +162,13 @@ public class MskService implements ResourceProvider { } public MskConfiguration describeConfiguration(String arn) { + // Real MSK reports an unknown configuration ARN as BadRequestException (400), not + // NotFoundException. The message prefix is a compatibility contract: terraform-provider-aws + // (and the Pulumi provider bridging it) substring-matches "Configuration ARN does not exist" + // to detect that a configuration is gone, so its post-delete waiter can complete. return configurationStorage.get(arn) - .orElseThrow(() -> new AwsException("NotFoundException", "Configuration not found: " + arn, 404)); + .orElseThrow(() -> new AwsException("BadRequestException", + "Configuration ARN does not exist: " + arn, 400)); } public PaginatedResult listConfigurations(Integer maxResults, String nextToken) { diff --git a/src/test/java/io/github/hectorvent/floci/services/msk/MskControllerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/msk/MskControllerIntegrationTest.java index a713c00b68..720f03722c 100644 --- a/src/test/java/io/github/hectorvent/floci/services/msk/MskControllerIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/msk/MskControllerIntegrationTest.java @@ -8,6 +8,7 @@ import java.util.Base64; import java.util.UUID; import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItem; @@ -126,11 +127,16 @@ class MskControllerIntegrationTest { .body("arn", equalTo(arn)) .body("state", equalTo("DELETING")); + // Real MSK signals a deleted configuration as BadRequestException, and the terraform/pulumi + // provider's delete waiter only recognizes that code plus this exact message substring as + // "gone" - assert the full wire contract, not just a status code. given() .when() .get("/v1/configurations/{arn}", arn) .then() - .statusCode(404); + .statusCode(400) + .header("X-Amzn-Errortype", equalTo("BadRequestException")) + .body("message", containsString("Configuration ARN does not exist")); } // An empty base64 blob decodes to "" and means "no property overrides". Absent and @@ -242,12 +248,14 @@ class MskControllerIntegrationTest { } @Test - void describeConfigurationReturnsNotFoundForUnknownArn() { + void describeConfigurationReturnsBadRequestForUnknownArn() { given() .when() .get("/v1/configurations/{arn}", "arn:aws:kafka:us-east-1:000000000000:configuration/missing/id") .then() - .statusCode(404); + .statusCode(400) + .header("X-Amzn-Errortype", equalTo("BadRequestException")) + .body("message", containsString("Configuration ARN does not exist")); } // kafkaVersions is optional on CreateConfigurationRequest. Omitting it must not leak a @@ -421,14 +429,16 @@ class MskControllerIntegrationTest { } @Test - void updateConfigurationReturnsNotFoundForUnknownArn() { + void updateConfigurationReturnsBadRequestForUnknownArn() { given() .contentType("application/json") .body("{\"serverProperties\": \"cHJvcHM=\"}") .when() .put("/v1/configurations/{arn}", "arn:aws:kafka:us-east-1:000000000000:configuration/missing/id") .then() - .statusCode(404); + .statusCode(400) + .header("X-Amzn-Errortype", equalTo("BadRequestException")) + .body("message", containsString("Configuration ARN does not exist")); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/msk/MskServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/msk/MskServiceTest.java index 4c0568ef2a..a495657019 100644 --- a/src/test/java/io/github/hectorvent/floci/services/msk/MskServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/msk/MskServiceTest.java @@ -183,9 +183,14 @@ class MskServiceTest { } @Test - void describeConfigurationNotFoundThrows() { - assertThrows(AwsException.class, () -> + void describeConfigurationUnknownArnThrowsBadRequest() { + // Real MSK uses BadRequestException with this message for unknown configuration ARNs; + // terraform-provider-aws substring-matches it to detect a deleted configuration. + AwsException ex = assertThrows(AwsException.class, () -> mskService.describeConfiguration("arn:aws:kafka:us-east-1:000000000000:configuration/missing/id")); + assertEquals("BadRequestException", ex.getErrorCode()); + assertEquals(400, ex.getHttpStatus()); + assertTrue(ex.getMessage().contains("Configuration ARN does not exist")); } @Test @@ -237,6 +242,18 @@ class MskServiceTest { assertTrue(mskService.listConfigurations(null, null).items().isEmpty()); } + @Test + void describeConfigurationAfterDeleteThrowsBadRequest() { + MskConfiguration configuration = mskService.createConfiguration( + "test-config", "desc", List.of("3.6.0"), "props"); + mskService.deleteConfiguration(configuration.getArn()); + + AwsException ex = assertThrows(AwsException.class, () -> + mskService.describeConfiguration(configuration.getArn())); + assertEquals("BadRequestException", ex.getErrorCode()); + assertTrue(ex.getMessage().contains("Configuration ARN does not exist")); + } + @Test void updateConfiguration() { MskConfiguration created = mskService.createConfiguration( @@ -284,10 +301,13 @@ class MskServiceTest { } @Test - void updateConfigurationNotFoundThrows() { - assertThrows(AwsException.class, () -> + void updateConfigurationUnknownArnThrowsBadRequest() { + AwsException ex = assertThrows(AwsException.class, () -> mskService.updateConfiguration( "arn:aws:kafka:us-east-1:000000000000:configuration/missing/id", "desc", "props")); + assertEquals("BadRequestException", ex.getErrorCode()); + assertEquals(400, ex.getHttpStatus()); + assertTrue(ex.getMessage().contains("Configuration ARN does not exist")); } @Test