fix(msk): return BadRequestException when a configuration ARN does not exist (#2572)

* fix(msk): return BadRequestException when a configuration ARN does not exist

Real MSK reports an unknown or deleted configuration ARN as
BadRequestException (400) with a message containing "Configuration ARN
does not exist", not NotFoundException (404). terraform-provider-aws
(and the Pulumi provider bridging it) substring-matches exactly that
code and message to detect a deleted configuration, so with the 404 the
provider's post-delete waiter never recognizes the configuration as
gone and every terraform/pulumi destroy of aws_msk_configuration fails.

All configuration operations resolve ARNs through
MskService#describeConfiguration, so Describe/Update/Delete and the
revision actions now share the corrected error shape. Cluster APIs are
untouched: real MSK does use NotFoundException there.

* test(msk): assert status, message and error-type header on unknown-ARN update tests
This commit is contained in:
Matan Baruch authored and GitHub committed 2026-08-25 23:40:02 -05:00
1 parent 399bf20387
commit 247bd590bc
3 files changed
+45 -10

No files matched your search

@@ -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<MskConfiguration> listConfigurations(Integer maxResults, String nextToken) {
@@ -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
@@ -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