feat(cloudformation): report a stubbed unsupported resource type instead of hiding it (#2971)

An unsupported resource type was stubbed at debug, so the stack reached CREATE_COMPLETE and a green stack did not prove its resources existed.

The stub is now reported at warn, naming the type, and the resource carries a status reason saying nothing was created, which DescribeStackEvents returns. A new floci.services.cloudformation.allow-stub-unsupported-resource-types setting (default true) turns the stub into a stack failure for suites that need a green stack to mean every resource exists. An unexpanded SAM resource type warns on its own, and the delete path names the physical id it does not remove.

Closes #2967
This commit is contained in:
Facundo Paredes authored and GitHub committed 2026-09-02 20:22:49 -05:00
1 parent 9e2c03158d
commit 5dc0808bda
10 files changed
+419 -5

No files matched your search

@@ -1420,6 +1420,20 @@ public interface EmulatorConfig {
*/
@WithDefault("false")
boolean allowStubLambdaCode();
/**
* Whether a resource whose type Floci has no provisioner for may be stubbed: a synthetic
* physical id, an {@code arn:aws:stub:::} ARN attribute and {@code CREATE_COMPLETE}.
*
* <p>Defaults to {@code true}, because Floci implements a fraction of the CloudFormation
* registry and failing every other type would reject templates that are valid to AWS. The
* stub is reported at warn and carries a resource status reason saying nothing was created,
* so a {@code CREATE_COMPLETE} stack can still be read as one where some resources exist
* only on paper. Set to {@code false} to fail such a resource instead, which rolls the
* stack back, for a pipeline that must not pass over a resource it never got.
*/
@WithDefault("true")
boolean allowStubUnsupportedResourceTypes();
}
interface AcmServiceConfig {
@@ -374,7 +374,12 @@ public class CloudFormationResourceProvisioner {
/**
* Provisions a single resource. Returns the populated StackResource (physicalId + attributes set).
* Returns null and logs a warning for unsupported types.
*
* <p>A resource type with no provisioner is stubbed: a synthetic physical id, an
* {@code arn:aws:stub:::} ARN attribute and {@code CREATE_COMPLETE}, logged at warn and
* carrying a status reason saying nothing was created. With
* {@code floci.services.cloudformation.allow-stub-unsupported-resource-types} off it comes back
* {@code CREATE_FAILED} instead, with no physical id.
*/
public StackResource provision(String logicalId, String resourceType, JsonNode properties,
CloudFormationTemplateEngine engine, String region, String accountId,
@@ -516,8 +521,26 @@ public class CloudFormationResourceProvisioner {
throw new IllegalStateException("No switch arm for declared legacy type "
+ resourceType + " — remove its LEGACY_SWITCH_TYPES entry when it "
+ "moves to a per-service provisioner.");
} else if (!stubUnsupportedResourceTypesAllowed()) {
// Before the physical id below is assigned, so the Cloud Control path sees
// a resource with none and reports this message rather than a success. On
// the stack path the catch below turns it into CREATE_FAILED with the same
// sentence, which rolls the stack back.
throw new AwsException("ValidationError",
unsupportedResourceTypeMessage(resourceType), 400);
} else {
LOG.debugv("Stubbing unsupported resource type: {0} ({1})", resourceType, logicalId);
// Warn, not debug, and a status reason on the resource: the stub reports
// CREATE_COMPLETE while creating nothing, so without both the stack is
// indistinguishable from one where every resource was really provisioned.
// The reason reaches DescribeStackEvents through the event
// CloudFormationService already builds from it.
LOG.warnv("Stubbing unsupported resource type {0} ({1}): nothing is created "
+ "for it. Set floci.services.cloudformation."
+ "allow-stub-unsupported-resource-types=false to fail the "
+ "stack instead.",
resourceType, logicalId);
resource.setStatusReason(unsupportedResourceTypeMessage(resourceType)
+ " It was stubbed and nothing was created for it.");
resource.setPhysicalId(logicalId + "-" + UUID.randomUUID().toString().substring(0, 8));
resource.getAttributes().put("Arn", "arn:aws:stub:::" + logicalId);
}
@@ -532,6 +555,20 @@ public class CloudFormationResourceProvisioner {
return resource;
}
/**
* Whether a resource type with no provisioner may be stubbed. The provisioners hand-built in
* unit tests carry no config; absent configuration means the documented default, which here is
* the lenient behaviour, so the test reads {@code config == null ||}.
*/
private boolean stubUnsupportedResourceTypesAllowed() {
return config == null || config.services().cloudformation().allowStubUnsupportedResourceTypes();
}
/** The one sentence Floci says about a resource type it has no provisioner for. */
static String unsupportedResourceTypeMessage(String resourceType) {
return "Resource type " + resourceType + " is not supported by Floci.";
}
/**
* Provision a single resource with no enclosing CloudFormation stack — the Cloud Control
* {@code CreateResource} path. Cloud Control DesiredState carries resolved values (no
@@ -735,7 +772,13 @@ public class CloudFormationResourceProvisioner {
case "AWS::AutoScaling::AutoScalingGroup" ->
autoScalingService.deleteAutoScalingGroup(region, physicalId, true);
case "AWS::CloudFront::Distribution" -> cloudFrontService.removeDistribution(physicalId);
default -> LOG.debugv("Skipping delete of unsupported resource type: {0}", resourceType);
// Warn for the same reason the create path does: the delete reports success over a
// type nothing here removes, and at debug that is invisible at the default log level.
// The line names the physical id without claiming a resource survives it: this arm
// takes both a type the create switch provisioned and one it only stubbed, and only
// the first leaves something behind.
default -> LOG.warnv("No delete implemented for resource type {0}: {1} is not removed "
+ "here.", resourceType, physicalId);
}
}
@@ -127,7 +127,10 @@ class SamTransformProcessor {
// copyResourceLevelAttributes runs inside expandServerlessStateMachine
// itself (its one caller already owning the source resDef).
expandServerlessStateMachine(logicalId, resDef, expandedResources);
default -> LOG.debugv("Unsupported SAM resource type: {0} ({1})", type, logicalId);
// Warn: the type stays in the template and the provisioner stubs it, so at debug
// this is the first of two silences on one path and the stack still reports green.
default -> LOG.warnv("Unsupported SAM resource type {0} ({1}): left in the "
+ "template for the CloudFormation provisioner.", type, logicalId);
}
}