From db86fc7d723607086ffd55d86887176d7b9d3f0c Mon Sep 17 00:00:00 2001 From: kenny-ish <114967656+kenny-ish@users.noreply.github.com> Date: Wed, 28 Oct 2026 18:24:01 +0700 Subject: [PATCH] fix(cloudmap): keep an empty HealthCheckCustomConfig and report FailureThreshold 1 (#6792) CreateService dropped a HealthCheckCustomConfig sent as {}. The handler passed it through rawJson, which returns null for an empty object, so the CreateService, GetService and ListServices responses left the field out. Terraform sends {} when failure_threshold is unset and then sees a change to the block on every plan. FailureThreshold is no longer supported, and the Cloud Map API reference says AWS always sets it to 1. The handler now keeps an empty object for this field, and CloudMapService stores {"FailureThreshold":1} for any HealthCheckCustomConfig, so a service created through CloudFormation reads back the same way. Fixes #6751 --- .../services/cloudmap/CloudMapHandler.java | 7 ++++- .../services/cloudmap/CloudMapService.java | 4 ++- .../cloudmap/CloudMapIntegrationTest.java | 28 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapHandler.java b/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapHandler.java index 7b8972ad14..64069a5baf 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapHandler.java @@ -151,7 +151,7 @@ public class CloudMapHandler { Service created = service.createService( text(request, "Name"), text(request, "NamespaceId"), text(request, "CreatorRequestId"), text(request, "Description"), rawJson(request.path("DnsConfig")), - rawJson(request.path("HealthCheckConfig")), rawJson(request.path("HealthCheckCustomConfig")), + rawJson(request.path("HealthCheckConfig")), objectJson(request.path("HealthCheckCustomConfig")), text(request, "Type"), parseTags(request), region); ObjectNode response = objectMapper.createObjectNode(); response.set("Service", buildServiceNode(created)); @@ -436,6 +436,11 @@ public class CloudMapHandler { return (node != null && node.isObject() && !node.isEmpty()) ? node.toString() : null; } + /** Unlike {@link #rawJson}, keeps {@code {}}: an empty HealthCheckCustomConfig still enables it. */ + private String objectJson(JsonNode node) { + return node.isObject() ? node.toString() : null; + } + private void setRawJson(ObjectNode target, String field, String rawJson) { if (rawJson == null) { return; diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapService.java b/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapService.java index e3e8d2db81..9186fd8853 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapService.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapService.java @@ -59,6 +59,8 @@ public class CloudMapService { private static final String ALNUM = "abcdefghijklmnopqrstuvwxyz0123456789"; /** Route 53 answers a service discovery query with at most eight records. */ private static final int MAX_DNS_ANSWERS = 8; + /** FailureThreshold is no longer supported: AWS always sets it to 1. */ + private static final String HEALTH_CHECK_CUSTOM_CONFIG = "{\"FailureThreshold\":1}"; private final SecureRandom random = new SecureRandom(); @@ -227,7 +229,7 @@ public class CloudMapService { service.setDescription(description); service.setDnsConfig(dnsConfig); service.setHealthCheckConfig(healthCheckConfig); - service.setHealthCheckCustomConfig(healthCheckCustomConfig); + service.setHealthCheckCustomConfig(healthCheckCustomConfig == null ? null : HEALTH_CHECK_CUSTOM_CONFIG); service.setType(resolveServiceType(type, dnsConfig)); service.setCreatorRequestId(creatorRequestId != null ? creatorRequestId : UUID.randomUUID().toString()); service.setCreateDate(Instant.now()); diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudmap/CloudMapIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudmap/CloudMapIntegrationTest.java index 107c292c2b..e920cf411d 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudmap/CloudMapIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudmap/CloudMapIntegrationTest.java @@ -193,4 +193,32 @@ class CloudMapIntegrationTest { .then().statusCode(404) .body("__type", equalTo("NamespaceNotFound")); } + + @Test + @Order(13) + void healthCheckCustomConfigAlwaysReadsBackFailureThresholdOne() { + String operationId = call("CreateHttpNamespace", "{\"Name\":\"floci-cm-custom-health\"}") + .then().statusCode(200) + .extract().jsonPath().getString("OperationId"); + String customNamespaceId = call("GetOperation", "{\"OperationId\":\"" + operationId + "\"}") + .then().statusCode(200) + .extract().jsonPath().getString("Operation.Targets.NAMESPACE"); + String emptyId = createCustomHealthService("empty", customNamespaceId, "{}"); + String thresholdId = createCustomHealthService("threshold", customNamespaceId, "{\"FailureThreshold\":3}"); + + for (String id : List.of(emptyId, thresholdId)) { + call("GetService", "{\"Id\":\"" + id + "\"}") + .then().statusCode(200) + .body("Service.HealthCheckCustomConfig.FailureThreshold", equalTo(1)); + call("DeleteService", "{\"Id\":\"" + id + "\"}").then().statusCode(200); + } + call("DeleteNamespace", "{\"Id\":\"" + customNamespaceId + "\"}").then().statusCode(200); + } + + private static String createCustomHealthService(String name, String nsId, String healthCheckCustomConfig) { + return call("CreateService", "{\"Name\":\"" + name + "\",\"NamespaceId\":\"" + nsId + + "\",\"HealthCheckCustomConfig\":" + healthCheckCustomConfig + "}") + .then().statusCode(200) + .extract().jsonPath().getString("Service.Id"); + } }