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

@@ -661,3 +661,17 @@ output "guardduty_detector_id" {
output "large_object_checksum_sha256" {
value = aws_s3_object.large.checksum_sha256
}
# -- Transfer Family Server (issue #2802) --------------------------------------
# Never stopped, so destroy exercises DeleteServer against an ONLINE server.
resource "aws_transfer_server" "compat" {
protocols = ["SFTP"]
tags = {
Environment = "compat-test"
}
}
output "transfer_server_id" {
value = aws_transfer_server.compat.id
}
@@ -443,3 +443,9 @@ sha256_composite_by_sizes() {
assert_success
assert_output "ALL"
}
@test "OpenTofu: Transfer Family server created and ONLINE" {
run aws_cmd transfer list-servers --query "Servers[0].State" --output text
assert_success
assert_output "ONLINE"
}
@@ -838,3 +838,17 @@ output "guardduty_detector_arn" {
output "large_object_checksum_sha256" {
value = aws_s3_object.large.checksum_sha256
}
# -- Transfer Family Server (issue #2802) --------------------------------------
# Never stopped, so destroy exercises DeleteServer against an ONLINE server.
resource "aws_transfer_server" "compat" {
protocols = ["SFTP"]
tags = {
Environment = "compat-test"
}
}
output "transfer_server_id" {
value = aws_transfer_server.compat.id
}
@@ -608,3 +608,9 @@ sha256_composite_by_sizes() {
fi
[ "$status" -eq 0 ]
}
@test "Terraform: Transfer Family server created and ONLINE" {
run aws_cmd transfer list-servers --query "Servers[0].State" --output text
assert_success
assert_output "ONLINE"
}
+1 -1
View File
@@ -15,7 +15,7 @@ AWS Transfer Family managed file transfer server management. This implementation
| `CreateServer` | Create a managed file transfer server |
| `DescribeServer` | Get server metadata and configuration |
| `UpdateServer` | Update protocols, endpoint type, logging role, security policy |
| `DeleteServer` | Delete a server (must be in `OFFLINE` state) |
| `DeleteServer` | Delete a server in any state, along with its users |
| `ListServers` | Paginated list of servers |
| `StartServer` | Transition server from `OFFLINE` to `ONLINE` |
| `StopServer` | Transition server from `ONLINE` to `OFFLINE` |
@@ -63,6 +63,7 @@ public class TransferHandler {
// ── Server handlers ───────────────────────────────────────────────────────
private Response createServer(JsonNode req, String region) {
String domain = textOrNull(req, "Domain");
List<String> protocols = jsonStringList(req.path("Protocols"));
String endpointType = textOrNull(req, "EndpointType");
Map<String, Object> endpointDetails = jsonObjectMap(req.path("EndpointDetails"));
@@ -72,7 +73,7 @@ public class TransferHandler {
String securityPolicyName = textOrNull(req, "SecurityPolicyName");
Map<String, String> tags = parseTags(req.path("Tags"));
Server server = service.createServer(region, protocols, endpointType, endpointDetails,
Server server = service.createServer(region, domain, protocols, endpointType, endpointDetails,
identityProviderType, identityProviderDetails, loggingRole, securityPolicyName, tags);
ObjectNode resp = objectMapper.createObjectNode();
@@ -277,6 +278,7 @@ public class TransferHandler {
node.put("ServerId", s.getServerId());
node.put("Arn", s.getArn());
node.put("State", s.getState());
node.put("Domain", s.getDomain());
node.put("EndpointType", s.getEndpointType());
node.put("IdentityProviderType", s.getIdentityProviderType());
node.put("SecurityPolicyName", s.getSecurityPolicyName());
@@ -304,6 +306,7 @@ public class TransferHandler {
private ObjectNode buildServerListEntry(Server s) {
ObjectNode node = objectMapper.createObjectNode();
node.put("Arn", s.getArn());
node.put("Domain", s.getDomain());
node.put("EndpointType", s.getEndpointType());
node.put("IdentityProviderType", s.getIdentityProviderType());
node.put("ServerId", s.getServerId());
@@ -44,6 +44,7 @@ public class TransferService {
// ── Servers ───────────────────────────────────────────────────────────────
public Server createServer(String region,
String domain,
List<String> protocols,
String endpointType,
Map<String, Object> endpointDetails,
@@ -59,6 +60,7 @@ public class TransferService {
server.setServerId(serverId);
server.setArn(arn);
server.setState("ONLINE");
server.setDomain(domain != null ? domain : "S3");
server.setProtocols(protocols != null && !protocols.isEmpty() ? protocols : List.of("SFTP"));
server.setEndpointType(endpointType != null ? endpointType : "PUBLIC");
server.setEndpointDetails(endpointDetails);
@@ -86,11 +88,9 @@ public class TransferService {
}
public synchronized void deleteServer(String serverId) {
Server server = getServer(serverId);
if (!"OFFLINE".equals(server.getState())) {
throw new AwsException("ConflictException",
"Server must be in OFFLINE state to be deleted.", 409);
}
// AWS deletes a server in any state: the DeleteServer API defines no
// state precondition (and no ConflictException at all).
getServer(serverId);
serverStore.delete(serverId);
tagStore.delete("server/" + serverId);
for (User user : userStore.scan(k -> k.startsWith(serverId + "/"))) {
@@ -12,6 +12,7 @@ public class Server {
private String serverId;
private String arn;
private String state;
private String domain;
private List<String> protocols;
private String endpointType;
private Map<String, Object> endpointDetails;
@@ -34,6 +35,9 @@ public class Server {
public String getState() { return state; }
public void setState(String state) { this.state = state; }
public String getDomain() { return domain; }
public void setDomain(String domain) { this.domain = domain; }
public List<String> getProtocols() { return protocols; }
public void setProtocols(List<String> protocols) { this.protocols = protocols; }
@@ -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"));
}
}