fix(cloudformation): resolve FunctionResponseTypes through whole-property intrinsics (#2996)

* fix(cloudformation): resolve FunctionResponseTypes through whole-property intrinsics

Greptile review on #2964 (merged): resolveStringList checked isArray()
on the raw, unresolved property node, so a whole-property intrinsic
like Fn::If, Fn::Split, or a Ref to a CommaDelimitedList parameter was
silently rejected instead of evaluated, leaving FunctionResponseTypes
empty for otherwise-valid templates. hectorvent merged #2964 anyway,
treating this as an acceptable known limitation given the property's
narrow value domain, but it turned out to be a self-correction I
should have caught: this same file already has resolveStringListOrEmpty,
which resolves the whole property through resolveNode first, and
swapping to it is a straight improvement with no downside for the
plain-array case.

That still needed a real fix underneath it: resolveNode treated Fn::If
as a scalar-collapsing intrinsic like Ref/Fn::Sub, so it stringified
a chosen array or object branch instead of preserving it. This is the
same engine gap Greptile flagged on PR #2796 (ScheduleGroup Tags),
which hectorvent asked to be raised separately rather than fixed in
that PR. Since a real fix was needed here to close this issue's gap
for good, resolveNode now special-cases Fn::If: it picks the branch
the same way resolve() does, then resolves that branch recursively
instead of collapsing it, so the result keeps whatever shape the
chosen branch actually has. resolve() itself is unchanged.

Verified by disabling each fix independently and confirming the
corresponding test fails with the exact expected error before
restoring it. Full cloudformation package regression (1272 tests)
passes clean.

* fix(cloudformation): use resolveList for FunctionResponseTypes, not resolveStringListOrEmpty

Greptile review on this PR: resolveStringListOrEmpty routes through
resolveNode, so it now sees an Fn::If-wrapped list, but resolveNode
never implemented real list-splitting logic - it just special-cases
which intrinsics collapse to a scalar. Fn::Split and a Ref to a
CommaDelimitedList parameter still resolved to a bare string there,
so resolveStringListOrEmpty's isArray() check still rejected them.

The engine already has a purpose-built method for exactly this,
resolveList, which correctly handles a literal array, Fn::GetAZs,
Fn::Cidr, Fn::Split (with its actual delimiter), and a comma-delimited
scalar (a Ref to a CommaDelimitedList parameter). It only needed
Fn::If added, the same way resolveNode gained it: pick the branch,
then resolve that branch through resolveList itself rather than
collapsing it, so a list-shaped branch (a literal array or another
Fn::Split) stays list-shaped.

Made resolveList public and switched provisionLambdaEventSourceMapping
to call it directly for FunctionResponseTypes, closing the gap for
Fn::If, Fn::Split, and CommaDelimitedList Refs in one pass instead of
leaving Fn::Split and CommaDelimitedList as a known follow-up gap.

Verified by disabling the new Fn::If branch in resolveList and
confirming the test fails with the exact expected wrong value before
restoring it - the first version of that test used comma-friendly data
that passed either way, so it was rewritten with a non-comma delimiter
to actually discriminate. Full cloudformation package regression
(1276 tests) passes clean.

* fix(cloudformation): route FunctionResponseTypes through resolveStringList, not resolveList

hectorvent (review): since #2946, the provisioner's resolveStringList
helper already delegates to engine.resolveStringList, which handles
Fn::If/Fn::Split/CommaDelimitedList and drops blank entries - making the
resolveList hunk from this PR redundant, and worse: resolveList keeps
blanks, so a conditional element resolving to AWS::NoValue was forwarded
as an invalid empty-string response type (also flagged by Greptile).

Drops the resolveList call in favor of the existing resolveStringList
helper, makes resolveList private again (its only external caller was
this now-removed hunk), and points the engine tests at resolveStringList.
Adds a test pinning the NoValue-drops-the-entry behavior Greptile flagged.
This commit is contained in:
Olamide Kosile authored and GitHub committed 2026-09-07 14:51:02 -05:00
1 parent 50836bbdc8
commit 9eb4fc82cd
3 files changed
+237 -13

No files matched your search

@@ -120,8 +120,17 @@ public class CloudFormationTemplateEngine {
return node;
}
if (node.isObject()) {
if (node.has("Fn::If")) {
// Unlike the other intrinsics below, Fn::If's two branches can be any JSON shape
// (array, object, or scalar) - it just forwards one of them verbatim. Collapsing it
// through resolve() like the scalar-only intrinsics would stringify a chosen array or
// object instead of preserving it, so a conditional list (e.g. a Tags property) reads
// as unresolvable everywhere a caller checks isArray() on the result.
JsonNode branch = selectIfBranch(node.get("Fn::If"));
return branch == null ? TextNode.valueOf("") : resolveNode(branch);
}
if (node.has("Ref") || node.has("Fn::Sub") || node.has("Fn::Join") ||
node.has("Fn::Select") || node.has("Fn::If") || node.has("Fn::Base64") ||
node.has("Fn::Select") || node.has("Fn::Base64") ||
node.has("Fn::GetAtt") || node.has("Fn::ImportValue") || node.has("Fn::Split") ||
node.has("Fn::GetAZs") || node.has("Fn::Cidr") || node.has("Fn::FindInMap")) {
return TextNode.valueOf(resolve(node));
@@ -261,8 +270,8 @@ public class CloudFormationTemplateEngine {
/**
* Resolves a node that represents a list — a literal array, a list-producing intrinsic
* ({@code Fn::GetAZs}, {@code Fn::Cidr}, {@code Fn::Split}), or a comma-delimited scalar
* (e.g. a {@code Ref} to a {@code List<>} parameter).
* ({@code Fn::GetAZs}, {@code Fn::Cidr}, {@code Fn::Split}), an {@code Fn::If} choosing between
* two such lists, or a comma-delimited scalar (e.g. a {@code Ref} to a {@code List<>} parameter).
*/
private List<String> resolveList(JsonNode node) {
List<String> out = new ArrayList<>();
@@ -273,6 +282,14 @@ public class CloudFormationTemplateEngine {
return resolveListElements(node);
}
if (node.isObject()) {
if (node.has("Fn::If")) {
// Fn::If's branch can itself be any of the shapes this method already handles
// (literal array, Fn::Split, ...), so recurse into it rather than falling through
// to the scalar branch below, which would stringify a list-shaped branch instead
// of splitting it.
JsonNode branch = selectIfBranch(node.get("Fn::If"));
return branch == null ? out : resolveList(branch);
}
if (node.has("Fn::GetAZs")) {
return resolveAvailabilityZones(node.get("Fn::GetAZs"));
}
@@ -282,14 +299,6 @@ public class CloudFormationTemplateEngine {
if (node.has("Fn::Split")) {
return resolveSplit(node.get("Fn::Split"));
}
if (node.has("Fn::If")) {
JsonNode ifNode = node.get("Fn::If");
if (ifNode.isArray() && ifNode.size() >= 3) {
String conditionName = ifNode.get(0).asText();
boolean condValue = conditions.getOrDefault(conditionName, false);
return resolveList(condValue ? ifNode.get(1) : ifNode.get(2));
}
}
}
String scalar = resolve(node);
if (!scalar.isEmpty()) {
@@ -448,12 +457,19 @@ public class CloudFormationTemplateEngine {
}
private String resolveIf(JsonNode ifNode) {
JsonNode branch = selectIfBranch(ifNode);
return branch == null ? "" : resolve(branch);
}
/** Picks Fn::If's true/false branch without resolving it further, so the caller decides
* whether to collapse it to a scalar ({@link #resolve}) or preserve its shape ({@link #resolveNode}). */
private JsonNode selectIfBranch(JsonNode ifNode) {
if (!ifNode.isArray() || ifNode.size() < 3) {
return "";
return null;
}
String conditionName = ifNode.get(0).asText();
boolean condValue = conditions.getOrDefault(conditionName, false);
return resolve(condValue ? ifNode.get(1) : ifNode.get(2));
return condValue ? ifNode.get(1) : ifNode.get(2);
}
private String resolveGetAtt(JsonNode getAtt) {