From 5beb8d47b99b134693843f46f76edcfcba07537b Mon Sep 17 00:00:00 2001
From: lex00 <121451605+lex00@users.noreply.github.com>
Date: Wed, 21 Oct 2026 21:09:42 -0600
Subject: [PATCH] fix(cloudformation): keep Route 53 routing policies and
provision health checks (#6191)
A Route 53 RecordSet resource now writes Region, Failover, Weight and
HealthCheckId into the record, as ChangeResourceRecordSets stores them.
A HealthCheck resource creates a health check with its tags, and its Ref
and HealthCheckId attribute return the check's id. An unknown Type is
refused before any check is created. Changing Type, RequestInterval or
MeasureLatency replaces the check, and the old one is deleted once the
update commits, or kept under UpdateReplacePolicy: Retain. Any other
change updates the check in place, and a failed stack update puts back
its earlier settings and tags.
---
docs/services/cloudformation.md | 2 +-
.../provisioners/CfnRollback.java | 7 +
.../provisioners/Route53CfnProvisioner.java | 298 +++++++++++++++-
...mationRoute53RecordSetIntegrationTest.java | 237 +++++++++++++
.../Route53CfnProvisionerTest.java | 333 ++++++++++++++++++
.../supported-resource-types.tsv | 1 +
tools/docs/cfn_resource_types.yaml | 2 +-
7 files changed, 876 insertions(+), 4 deletions(-)
diff --git a/docs/services/cloudformation.md b/docs/services/cloudformation.md
index aa1aaa0385..8fa42ca9ef 100644
--- a/docs/services/cloudformation.md
+++ b/docs/services/cloudformation.md
@@ -193,7 +193,7 @@ cross-resource references.
| Elastic Load Balancing v2 | `LoadBalancer`, `TargetGroup`, `Listener`, `ListenerRule` |
| Auto Scaling | `LaunchConfiguration`, `AutoScalingGroup`, `LifecycleHook`, `ScalingPolicy` |
| Application Auto Scaling | `ScalableTarget` (`ScheduledActions` are accepted and not run; Floci has no scheduled scaling), `ScalingPolicy` |
-| Route 53 | `HostedZone`, `RecordSet` |
+| Route 53 | `HostedZone`, `RecordSet`, `HealthCheck` |
| Cloud Map | `HttpNamespace`, `PrivateDnsNamespace`, `PublicDnsNamespace`, `Service` |
| API Gateway (v1) | `RestApi`, `Resource`, `Authorizer`, `Method`, `Deployment`, `Stage`, `Account`, `DomainName`, `BasePathMapping`, `GatewayResponse`, `ApiKey`, `UsagePlan`, `UsagePlanKey` |
| API Gateway v2 | `Api`, `Authorizer`, `Route`, `Integration`, `Stage`, `Deployment`, `DomainName`, `ApiMapping`, `VpcLink` |
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnRollback.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnRollback.java
index 88d1e701c8..429502eec6 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnRollback.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnRollback.java
@@ -101,6 +101,13 @@ public final class CfnRollback {
* {@code rollbackUpdate}.
*/
public static final String DASHBOARD_UPDATE_SNAPSHOT_ATTR = "__FlociDashboardUpdateSnapshot";
+
+ /**
+ * Holds the configuration and tags a Route 53 health check carried before an in-place update
+ * changed them, so a failed stack update can put them back. Written by
+ * {@code Route53CfnProvisioner} before its update call and spent by its {@code rollbackUpdate}.
+ */
+ public static final String HEALTH_CHECK_UPDATE_SNAPSHOT_ATTR = "__FlociRoute53HealthCheckUpdateSnapshot";
public static final String S3_BUCKET_UPDATE_SNAPSHOT_ATTR = "__FlociS3BucketUpdateSnapshot";
/**
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Route53CfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Route53CfnProvisioner.java
index b25d173ae5..6a58b7ae05 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Route53CfnProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Route53CfnProvisioner.java
@@ -1,10 +1,15 @@
package io.github.hectorvent.floci.services.cloudformation.provisioners;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.route53.Route53Service;
import io.github.hectorvent.floci.services.route53.model.AliasTarget;
+import io.github.hectorvent.floci.services.route53.model.HealthCheck;
+import io.github.hectorvent.floci.services.route53.model.HealthCheckConfig;
import io.github.hectorvent.floci.services.route53.model.HostedZone;
import io.github.hectorvent.floci.services.route53.model.ResourceRecord;
import io.github.hectorvent.floci.services.route53.model.ResourceRecordSet;
@@ -15,13 +20,16 @@ import org.jboss.logging.Logger;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.UUID;
/**
- * Provisions {@code AWS::Route53::HostedZone} and {@code AWS::Route53::RecordSet}.
+ * Provisions {@code AWS::Route53::HostedZone}, {@code AWS::Route53::RecordSet} and
+ * {@code AWS::Route53::HealthCheck}.
*
*
A record set is written into its hosted zone through {@code ChangeResourceRecordSets}. On stack
* create, and on an update that changes the record's identity (zone, Name, Type or SetIdentifier), the
@@ -38,6 +46,16 @@ import java.util.Set;
public class Route53CfnProvisioner implements CfnResourceProvisioner {
static final String HOSTED_ZONE = "AWS::Route53::HostedZone";
static final String RECORD_SET = "AWS::Route53::RecordSet";
+ static final String HEALTH_CHECK = "AWS::Route53::HealthCheck";
+
+ /** The registry schema's create-only HealthCheckConfig members. */
+ private static final List HEALTH_CHECK_CREATE_ONLY = List.of("Type", "RequestInterval", "MeasureLatency");
+ /** The registry schema's HealthCheckConfig.Type enum. */
+ private static final List HEALTH_CHECK_TYPES = List.of("CALCULATED", "CLOUDWATCH_METRIC", "HTTP",
+ "HTTP_STR_MATCH", "HTTPS", "HTTPS_STR_MATCH", "TCP", "RECOVERY_CONTROL");
+ // Describes the check as its public attributes do, so a replacement rollback puts it back.
+ private static final String HEALTH_CHECK_CREATE_ONLY_ATTR = CfnRollback.USES_ATTR_PREFIX + "Route53HealthCheckCreateOnly";
+ private static final ObjectMapper MAPPER = new ObjectMapper();
// Create-time values a record's delete needs to build a matching DELETE change; kept off the
// published attributes by the __Floci prefix, as the other provisioners do.
@@ -56,7 +74,7 @@ public class Route53CfnProvisioner implements CfnResourceProvisioner {
@Override
public Set resourceTypes() {
- return Set.of(HOSTED_ZONE, RECORD_SET);
+ return Set.of(HOSTED_ZONE, RECORD_SET, HEALTH_CHECK);
}
@Override
@@ -64,6 +82,7 @@ public class Route53CfnProvisioner implements CfnResourceProvisioner {
switch (resource.getResourceType()) {
case "AWS::Route53::HostedZone" -> provisionHostedZone(resource, props, ctx);
case "AWS::Route53::RecordSet" -> provisionRecordSet(resource, props, ctx);
+ case "AWS::Route53::HealthCheck" -> provisionHealthCheck(resource, props, ctx);
default -> throw new IllegalStateException(
"Route53CfnProvisioner received an unsupported type: " + resource.getResourceType());
}
@@ -103,6 +122,18 @@ public class Route53CfnProvisioner implements CfnResourceProvisioner {
rrs.setSetIdentifier(setIdentifier);
rrs.setRecords(parseResourceRecords(props, ctx));
rrs.setAliasTarget(parseAliasTarget(props, ctx));
+ rrs.setRegion(ctx.resolveOrDefault(props, "Region", null));
+ rrs.setFailover(ctx.resolveOrDefault(props, "Failover", null));
+ rrs.setHealthCheckId(ctx.resolveOrDefault(props, "HealthCheckId", null));
+ String weight = ctx.resolveOrDefault(props, "Weight", null);
+ if (weight != null) {
+ try {
+ rrs.setWeight(Long.parseLong(weight.trim()));
+ } catch (NumberFormatException e) {
+ throw new AwsException("ValidationError",
+ "AWS::Route53::RecordSet Weight must be an integer: " + weight, 400);
+ }
+ }
// The record's identity is Name + Type + SetIdentifier within a zone. Re-applying the identity
// this resource wrote last time is an UPSERT, which replaces whatever record holds that
@@ -230,6 +261,208 @@ public class Route53CfnProvisioner implements CfnResourceProvisioner {
return target;
}
+ /**
+ * Creates the health check, or updates it in place on a stack update. {@code Type},
+ * {@code RequestInterval} and {@code MeasureLatency} are create-only, so an update that changes
+ * one creates a new check; the displaced check is deleted once the update commits, or kept
+ * under {@code UpdateReplacePolicy: Retain}, through {@link ReplacementCleanup}. An in-place
+ * update first snapshots the check's configuration and tags, so a failed stack update can put
+ * them back. {@code Ref} and {@code Fn::GetAtt HealthCheckId} are the health check id.
+ */
+ private void provisionHealthCheck(StackResource resource, JsonNode props, ProvisionContext ctx) {
+ // A snapshot describes the update in flight; one an earlier update left behind is stale.
+ resource.getAttributes().remove(CfnRollback.HEALTH_CHECK_UPDATE_SNAPSHOT_ATTR);
+ if (ctx.isUpdate()) {
+ ReplacementCleanup.endRollbackRetry(resource);
+ }
+ Map attributesBefore = Map.copyOf(resource.getAttributes());
+
+ JsonNode resolved = ctx.engine().resolveNode(props);
+ JsonNode configNode = resolved != null ? resolved.path("HealthCheckConfig") : null;
+ if (configNode == null || !configNode.isObject()) {
+ throw new AwsException("ValidationError",
+ "AWS::Route53::HealthCheck requires HealthCheckConfig.", 400);
+ }
+ HealthCheckConfig config = parseHealthCheckConfig(configNode);
+ String createOnly = createOnlyValues(configNode);
+ Map tags = new LinkedHashMap<>();
+ parseTags(resolved.path("HealthCheckTags")).forEach(tag -> tags.put(tag.get("Key"), tag.get("Value")));
+
+ String priorId = ctx.isUpdate() ? ctx.priorPhysicalId() : null;
+ HealthCheck prior = priorId != null ? findHealthCheck(priorId) : null;
+ String id;
+ if (prior != null && createOnly.equals(priorCreateOnlyValues(resource, prior))) {
+ id = priorId;
+ snapshotBeforeUpdate(resource, prior);
+ try {
+ route53Service.updateHealthCheck(id, config);
+ reconcileHealthCheckTags(id, tags);
+ } catch (RuntimeException failure) {
+ unwindHealthCheckUpdate(resource, id, failure);
+ throw failure;
+ }
+ } else {
+ String callerReference = ctx.stackName() + "/" + resource.getLogicalId() + "/" + UUID.randomUUID();
+ id = route53Service.createHealthCheck(callerReference, config, configNode.toString()).getId();
+ try {
+ reconcileHealthCheckTags(id, tags);
+ } catch (RuntimeException failure) {
+ // The check this provision created is not yet the resource's, so nothing else removes it.
+ try {
+ route53Service.deleteHealthCheck(id);
+ } catch (RuntimeException cleanupFailure) {
+ failure.addSuppressed(cleanupFailure);
+ }
+ throw failure;
+ }
+ }
+
+ resource.setPhysicalId(id);
+ resource.getAttributes().put("HealthCheckId", id);
+ resource.getAttributes().put(HEALTH_CHECK_CREATE_ONLY_ATTR, createOnly);
+ ReplacementCleanup.record(resource, ctx, attributesBefore);
+ }
+
+ private HealthCheck findHealthCheck(String id) {
+ try {
+ return route53Service.getHealthCheck(id);
+ } catch (AwsException e) {
+ if (!"NoSuchHealthCheck".equals(e.getErrorCode())) {
+ throw e;
+ }
+ return null;
+ }
+ }
+
+ private void reconcileHealthCheckTags(String id, Map desired) {
+ List stale = ProvisionContext.staleTagKeys(
+ route53Service.listTagsForResource("healthcheck", id), desired);
+ List