fix(transfer): allow DeleteServer regardless of server state (#2897)

* fix(transfer): allow DeleteServer regardless of server state

AWS's DeleteServer API has no state precondition: its error list has no
ConflictException, and terraform-provider-aws's resourceServerDelete
calls DeleteServer directly without stopping the server first. The
OFFLINE-only guard made every terraform destroy of a running
aws_transfer_server fail with a 409 that real AWS never returns.

CreateServer's ONLINE default is left as is: it matches real AWS, where
a new server transitions STARTING -> ONLINE automatically without a
StartServer call, and terraform's waitServerCreated treats OFFLINE as
an unexpected state that fails apply immediately. Added an integration
test locking in both behaviors.

Fixes #2802

* fix(transfer): return Domain from DescribeServer and ListServers

Real AWS always reports a server's Domain (default S3). Floci dropped
the field on CreateServer and never echoed it, so terraform-provider-aws
read back "" into its ForceNew domain attribute (default "S3") and every
re-plan of an aws_transfer_server proposed a replacement:

  + domain = "S3" # forces replacement

Store Domain on create, defaulting to S3 like AWS, and include it in
DescribeServer and ListServers. Needed for the resource to survive the
whole-config re-plan assertion in the terraform compat suite.

* test(compat): add aws_transfer_server to the terraform and opentofu suites

The resource was pulled from both fixtures while #1834 iterated because
DeleteServer 409'd on a running server (#2802). With that fixed, put it
back: the server is never stopped, so terraform destroy hits DeleteServer
while it is ONLINE, and the existing whole-config re-plan test guards the
DescribeServer round trip.

* docs(transfer): drop the OFFLINE precondition from DeleteServer
This commit is contained in:
BingEdward authored and GitHub committed 2026-09-07 08:54:03 -04:00
1 parent 7a5ae965e5
commit e7256f5556
9 files changed
+239 -7

No files matched your search

@@ -0,0 +1,185 @@
package io.github.hectorvent.floci.services.transfer;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.startsWith;
/**
* Server lifecycle conformance (#2802): AWS's DeleteServer has no state
* precondition (terraform destroy deletes running servers directly, without
* calling StopServer first), and a newly created server ends up ONLINE
* (terraform's post-create waiter expects STARTING -> ONLINE, never OFFLINE).
*/
@QuarkusTest
class TransferServerLifecycleIntegrationTest {
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
private String createServer() {
return given()
.header("X-Amz-Target", "TransferService.CreateServer")
.contentType(CONTENT_TYPE)
.body("{}")
.when()
.post("/")
.then()
.statusCode(200)
.body("ServerId", startsWith("s-"))
.extract().jsonPath().getString("ServerId");
}
@Test
void createServerComesUpOnline() {
String serverId = createServer();
given()
.header("X-Amz-Target", "TransferService.DescribeServer")
.contentType(CONTENT_TYPE)
.body("{\"ServerId\": \"" + serverId + "\"}")
.when()
.post("/")
.then()
.statusCode(200)
.body("Server.ServerId", equalTo(serverId))
.body("Server.State", equalTo("ONLINE"));
}
// terraform-provider-aws reads Domain back from DescribeServer into a
// ForceNew attribute defaulting to S3; a missing field re-plans as a
// replacement on every run.
@Test
void describeServerReportsDomain() {
String defaulted = createServer();
given()
.header("X-Amz-Target", "TransferService.DescribeServer")
.contentType(CONTENT_TYPE)
.body("{\"ServerId\": \"" + defaulted + "\"}")
.when()
.post("/")
.then()
.statusCode(200)
.body("Server.Domain", equalTo("S3"));
String efs = given()
.header("X-Amz-Target", "TransferService.CreateServer")
.contentType(CONTENT_TYPE)
.body("{\"Domain\": \"EFS\"}")
.when()
.post("/")
.then()
.statusCode(200)
.extract().jsonPath().getString("ServerId");
given()
.header("X-Amz-Target", "TransferService.DescribeServer")
.contentType(CONTENT_TYPE)
.body("{\"ServerId\": \"" + efs + "\"}")
.when()
.post("/")
.then()
.statusCode(200)
.body("Server.Domain", equalTo("EFS"));
}
@Test
void deleteServerWhileOnline() {
String serverId = createServer();
// Never stopped, so still ONLINE - deletion must succeed anyway.
given()
.header("X-Amz-Target", "TransferService.DeleteServer")
.contentType(CONTENT_TYPE)
.body("{\"ServerId\": \"" + serverId + "\"}")
.when()
.post("/")
.then()
.statusCode(200);
given()
.header("X-Amz-Target", "TransferService.DescribeServer")
.contentType(CONTENT_TYPE)
.body("{\"ServerId\": \"" + serverId + "\"}")
.when()
.post("/")
.then()
.statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"));
}
@Test
void deleteServerWhileOffline() {
String serverId = createServer();
given()
.header("X-Amz-Target", "TransferService.StopServer")
.contentType(CONTENT_TYPE)
.body("{\"ServerId\": \"" + serverId + "\"}")
.when()
.post("/")
.then()
.statusCode(200);
given()
.header("X-Amz-Target", "TransferService.DeleteServer")
.contentType(CONTENT_TYPE)
.body("{\"ServerId\": \"" + serverId + "\"}")
.when()
.post("/")
.then()
.statusCode(200);
}
@Test
void deleteServerCascadesToUsers() {
String serverId = createServer();
given()
.header("X-Amz-Target", "TransferService.CreateUser")
.contentType(CONTENT_TYPE)
.body("""
{
"ServerId": "%s",
"UserName": "alice",
"Role": "arn:aws:iam::000000000000:role/transfer-role"
}
""".formatted(serverId))
.when()
.post("/")
.then()
.statusCode(200);
// Users no longer block deletion of a running server.
given()
.header("X-Amz-Target", "TransferService.DeleteServer")
.contentType(CONTENT_TYPE)
.body("{\"ServerId\": \"" + serverId + "\"}")
.when()
.post("/")
.then()
.statusCode(200);
}
@Test
void deleteMissingServerReturnsNotFound() {
given()
.header("X-Amz-Target", "TransferService.DeleteServer")
.contentType(CONTENT_TYPE)
.body("{\"ServerId\": \"s-00000000000000000\"}")
.when()
.post("/")
.then()
.statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"));
}
}