fix(cloudformation): read an ECS task definition's properties as the ECS handler does (#6018)

Measured on CloudFormation (eu-west-1): an AWS::ECS::TaskDefinition gets
no template validation. CloudFormation hands the ECS handler every
scalar as text, and the handler converts each to the type the resource
schema declares: an integer is a sign and digits once trimmed, within
32 bits ("+128", " 128", "0128"), and a boolean is true or false in
lower, upper or title case once trimmed. A value it cannot convert
("abc", 4.5 or true for an integer, "yes", "tRuE" or "1" for a
boolean), and an object, a list and a scalar standing for one another,
fail the resource with every violation of the unconverted model, where
every scalar is a String, so a Memory of 128 is listed beside the value
that failed. At each object its missing required members come first,
then its members in the schema's order. When every value converts, the
required members the model lacks fail it alone, grouped where their
paths meet as the schema validator groups them.

Floci read the properties as plain JSON: a Memory of "abc" and a
container without an image were registered, and an Essential of
"False" registered an essential container.

AWS::ECS::TaskDefinition joins the generated cfn-property-types.json,
whose structures now carry the members the schema requires, read into
RequestShapeModel's shapes. CfnPropertyTypes' walk over the shapes is
shared by the template validation Reader and the new HandlerReader,
which differ in how a scalar converts and in what a mismatch does.
This commit is contained in:
Alessandro Lattao authored and GitHub committed 2026-10-19 16:15:05 -04:00
1 parent e1d102f06b
commit fcb41966a8
12 files changed
+1596 -162

No files matched your search

@@ -3,23 +3,29 @@ package io.github.hectorvent.floci.core.common;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* The input shapes of a service's operations, as a {@code tools/aws/regen_*_shapes.py} generator
* vendors them from botocore: each operation's input shape, and for every shape reachable from one
* its type and the shapes of its structure members, list elements or map values. A service's
* its type, the shapes of its structure members and the ones it requires, or of its list elements or
* map values. A service's
* request check walks a body against it with {@link RequestShapeCheck} and its own messages.
*/
public record RequestShapeModel(Map<String, String> operations, Map<String, Shape> shapes) {
private static final ObjectMapper MAPPER = new ObjectMapper();
/** One shape: its type, the shape of each structure member, or the list element or map value shape. */
public record Shape(String type, Map<String, String> members, String element) {
/**
* One shape: its type, the shape of each structure member and the members it requires, or the
* list element or map value shape.
*/
public record Shape(String type, Map<String, String> members, String element, List<String> required) {
}
/** The vendored resource {@code name}; {@code description} names it in a failure. */
@@ -36,8 +42,10 @@ public record RequestShapeModel(Map<String, String> operations, Map<String, Shap
Map<String, String> members = new LinkedHashMap<>();
node.path("members").properties().forEach(m -> members.put(m.getKey(), m.getValue().asText()));
String element = node.hasNonNull("member") ? node.get("member").asText() : node.path("value").asText(null);
List<String> required = new ArrayList<>();
node.path("required").forEach(name -> required.add(name.asText()));
shapes.put(entry.getKey(), new Shape(node.path("type").asText(), Collections.unmodifiableMap(members),
element));
element, List.copyOf(required)));
}
return new RequestShapeModel(Map.copyOf(operations), Map.copyOf(shapes));
}
@@ -14,8 +14,11 @@ import io.github.hectorvent.floci.core.common.RequestShapeModel.Shape;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
/**
@@ -37,13 +40,18 @@ import java.util.regex.Pattern;
* <p>The resource handler's model validation runs after it, on the values CloudFormation converted,
* and names the whole path: a boolean that is not true or false in any case, and an integer beyond
* 32 bits, fail as "Model validation failed (#/Targets/0/EcsParameters/EnableECSManagedTags:
* expected type: Boolean, found: String)".
* expected type: Boolean, found: String)". Some resource types get no template validation, and
* their handler converts the values itself; {@link HandlerReader} reads those.
*/
final class CfnPropertyTypes {
static final String RESOURCE_NAME = "aws/cfn-property-types.json";
private static final String LIST = "JSONArray";
private static final Pattern WHOLE_NUMBER = Pattern.compile("-?\\d+");
private static final Pattern SIGNED_WHOLE_NUMBER = Pattern.compile("[+-]?\\d+");
private static final Set<String> TRUE_TEXT = Set.of("true", "True", "TRUE");
private static final Set<String> FALSE_TEXT = Set.of("false", "False", "FALSE");
private static final String INTEGER_RANGE_HINT = ". This may occur when a numeric value exceeds 32-bit"
+ " integer max (2147483647). Consider using 'number' type or ensure value fits in integer range.";
@@ -59,19 +67,23 @@ final class CfnPropertyTypes {
String properties = Holder.MODEL.operations().get(resourceType);
String shape = properties == null ? null : Holder.MODEL.shapes().get(properties).members().get(property);
if (shape == null) {
throw new IllegalStateException(resourceType + "." + property + " is not in " + RESOURCE_NAME
+ "; add the type to tools/aws/regen_cfn_property_types.py");
throw notVendored(resourceType + "." + property);
}
return shape;
}
private static IllegalStateException notVendored(String what) {
return new IllegalStateException(what + " is not in " + RESOURCE_NAME
+ "; add the type to tools/aws/regen_cfn_property_types.py");
}
/**
* Refuses a value of another type than {@code expected}, an object or a list, with template
* validation's message, where a number or a boolean reads as a String.
*/
static void requireType(String property, JsonNode value, JsonNodeType expected) {
if (value.getNodeType() != expected) {
throw templateMismatch(property, expected == JsonNodeType.OBJECT ? "JSONObject" : "JSONArray",
throw templateMismatch(property, expected == JsonNodeType.OBJECT ? "JSONObject" : LIST,
containerName(value));
}
}
@@ -86,8 +98,24 @@ final class CfnPropertyTypes {
* and {@code Fn::Split} (measured, eu-west-1, 2026-10-18).
*/
static List<String> readStringList(String property, JsonNode raw, CloudFormationTemplateEngine engine) {
String found = listType(raw, engine);
if (found == null) {
return null;
}
if (!LIST.equals(found)) {
throw templateMismatch(property, LIST, found);
}
return engine.resolveStringList(raw);
}
/**
* What a list-of-strings property written as {@code raw} yields, as {@link #readStringList}
* reads it: JSONArray for a list, null for {@code AWS::NoValue}, and otherwise the name of what
* it yields instead.
*/
private static String listType(JsonNode raw, CloudFormationTemplateEngine engine) {
if (raw.isValueNode()) {
requireType(property, raw, JsonNodeType.ARRAY);
return containerName(raw);
}
if (raw.isObject()) {
JsonNode resolved = engine.resolveNodeOmittingNoValue(raw);
@@ -95,25 +123,175 @@ final class CfnPropertyTypes {
return null;
}
if (resolved.isObject() || (!resolved.isArray() && engine.yieldsString(raw))) {
requireType(property, resolved, JsonNodeType.ARRAY);
return containerName(resolved);
}
}
return engine.resolveStringList(raw);
return LIST;
}
/**
* A walk over template values against the shapes the resource schemas declare, resolving them
* on the way. What {@code AWS::NoValue} stands for is left out, and members a shape does not
* declare are resolved as they are. How a scalar converts, and what a value of the wrong type
* does, is each reader's own.
*/
private abstract static class ShapeWalk {
final CloudFormationTemplateEngine engine;
final RequestShapeModel model;
ShapeWalk(CloudFormationTemplateEngine engine, RequestShapeModel model) {
this.engine = engine;
this.model = model;
}
/** A value of another type than {@code expected} at {@code path}, whose last name is {@code property}. */
abstract void mismatch(String path, String property, String expected, String found);
abstract JsonNode readInteger(String path, String property, JsonNode value);
abstract JsonNode readBoolean(String path, String property, JsonNode value);
/** Checks the members {@code shape} requires of the object {@code value} at {@code path}; none by default. */
void checkRequired(String path, JsonNode value, Shape shape) {
}
/** The members of the object {@code value} in the order they are read: the template's by default. */
Iterable<Map.Entry<String, JsonNode>> members(JsonNode value, Shape shape) {
return value.properties();
}
JsonNode read(String path, String property, JsonNode raw, String shapeName) {
if (raw == null || raw.isNull() || raw.isMissingNode()) {
return null;
}
Shape shape = model.shapes().get(shapeName);
if ("list".equals(shape.type()) && "string".equals(model.shapes().get(shape.element()).type())) {
return readStringList(path, property, raw);
}
JsonNode value = raw.isContainerNode() && !CloudFormationTemplateEngine.callsIntrinsic(raw)
? raw : engine.resolveNode(raw);
if (value == null || value.isNull() || value.isMissingNode()) {
return null;
}
return switch (shape.type()) {
case "structure" -> readObject(path, property, value, shape);
case "map" -> readMap(path, property, value, shape.element());
case "list" -> readList(path, property, value, shape.element());
case "string" -> readString(path, property, value);
case "integer" -> readInteger(path, property, value);
case "boolean" -> readBoolean(path, property, value);
default -> value == raw ? engine.resolveNode(raw) : value;
};
}
private boolean expect(String path, String property, JsonNode value, JsonNodeType expected) {
if (value.getNodeType() == expected) {
return true;
}
mismatch(path, property, expected == JsonNodeType.OBJECT ? "JSONObject" : LIST, containerName(value));
return false;
}
private JsonNode readObject(String path, String property, JsonNode value, Shape shape) {
if (!expect(path, property, value, JsonNodeType.OBJECT)) {
return null;
}
checkRequired(path, value, shape);
ObjectNode out = JsonNodeFactory.instance.objectNode();
for (Map.Entry<String, JsonNode> member : members(value, shape)) {
String memberShape = shape.members().get(member.getKey());
JsonNode read = memberShape == null ? engine.resolveNode(member.getValue())
: read(child(path, member.getKey()), member.getKey(), member.getValue(), memberShape);
if (read != null) {
out.set(member.getKey(), read);
}
}
return out;
}
private JsonNode readMap(String path, String property, JsonNode value, String valueShape) {
if (!expect(path, property, value, JsonNodeType.OBJECT)) {
return null;
}
ObjectNode out = JsonNodeFactory.instance.objectNode();
for (Map.Entry<String, JsonNode> entry : value.properties()) {
JsonNode read = read(child(path, entry.getKey()), entry.getKey(), entry.getValue(), valueShape);
if (read != null) {
out.set(entry.getKey(), read);
}
}
return out;
}
private JsonNode readList(String path, String property, JsonNode value, String itemShape) {
if (!expect(path, property, value, JsonNodeType.ARRAY)) {
return null;
}
ArrayNode out = JsonNodeFactory.instance.arrayNode();
for (int i = 0; i < value.size(); i++) {
JsonNode read = read(child(path, String.valueOf(i)), String.valueOf(i), value.get(i), itemShape);
if (read != null) {
out.add(read);
}
}
return out;
}
/**
* A literal list keeps its blank entries where the template put them, as CloudFormation
* passes it on, and an item that is an object or a list is refused by its index, as for any
* string; any other value is read as {@link CfnPropertyTypes#readStringList} says.
*/
private JsonNode readStringList(String path, String property, JsonNode raw) {
List<String> values;
if (raw.isArray()) {
boolean strings = true;
for (int i = 0; i < raw.size(); i++) {
JsonNode item = raw.get(i);
if (item.isContainerNode() && !CloudFormationTemplateEngine.callsIntrinsic(item)) {
mismatch(child(path, String.valueOf(i)), String.valueOf(i), "String", containerName(item));
strings = false;
}
}
values = strings ? engine.resolveLiteralList(raw) : null;
} else {
String found = listType(raw, engine);
if (found != null && !LIST.equals(found)) {
mismatch(path, property, LIST, found);
}
values = LIST.equals(found) ? engine.resolveStringList(raw) : null;
}
if (values == null) {
return null;
}
ArrayNode out = JsonNodeFactory.instance.arrayNode();
values.forEach(out::add);
return out;
}
private JsonNode readString(String path, String property, JsonNode value) {
if (value.isContainerNode()) {
mismatch(path, property, "String", containerName(value));
return null;
}
return value.isTextual() ? value : TextNode.valueOf(value.asText());
}
static String child(String path, String name) {
return path.isEmpty() ? name : path + "/" + name;
}
}
/**
* Reads template values against the shapes the resource schemas declare and resolves them,
* converting them as CloudFormation does before the handler sees them: an integer or a boolean
* given as text becomes one, and a number or a boolean where text is expected becomes text.
* Members a shape does not declare are resolved as they are. What {@code AWS::NoValue} stands for
* is left out. Template validation failures are thrown at once; the first model validation
* failure waits for {@link #finish}, so every value read has passed template validation first,
* as on AWS.
* Template validation failures are thrown at once; the first model validation failure waits for
* {@link #finish}, so every value read has passed template validation first, as on AWS.
*/
static final class Reader {
static final class Reader extends ShapeWalk {
private final CloudFormationTemplateEngine engine;
private final RequestShapeModel model;
private AwsException modelFailure;
Reader(CloudFormationTemplateEngine engine) {
@@ -121,8 +299,7 @@ final class CfnPropertyTypes {
}
Reader(CloudFormationTemplateEngine engine, RequestShapeModel model) {
this.engine = engine;
this.model = model;
super(engine, model);
}
/**
@@ -140,102 +317,13 @@ final class CfnPropertyTypes {
}
}
private JsonNode read(String path, String property, JsonNode raw, String shapeName) {
if (raw == null || raw.isNull() || raw.isMissingNode()) {
return null;
}
Shape shape = model.shapes().get(shapeName);
if ("list".equals(shape.type()) && "string".equals(model.shapes().get(shape.element()).type())) {
return readStringList(property, raw);
}
JsonNode value = raw.isContainerNode() && !CloudFormationTemplateEngine.callsIntrinsic(raw)
? raw : engine.resolveNode(raw);
if (value == null || value.isNull() || value.isMissingNode()) {
return null;
}
return switch (shape.type()) {
case "structure" -> readObject(path, property, value, shape.members());
case "map" -> readMap(path, property, value, shape.element());
case "list" -> readList(path, property, value, shape.element());
case "string" -> readString(property, value);
case "integer" -> readInteger(path, property, value);
case "boolean" -> readBoolean(path, property, value);
default -> value == raw ? engine.resolveNode(raw) : value;
};
@Override
void mismatch(String path, String property, String expected, String found) {
throw templateMismatch(property, expected, found);
}
private JsonNode readObject(String path, String property, JsonNode value, Map<String, String> members) {
requireType(property, value, JsonNodeType.OBJECT);
ObjectNode out = JsonNodeFactory.instance.objectNode();
for (Map.Entry<String, JsonNode> member : value.properties()) {
String memberShape = members.get(member.getKey());
JsonNode read = memberShape == null ? engine.resolveNode(member.getValue())
: read(path + "/" + member.getKey(), member.getKey(), member.getValue(), memberShape);
if (read != null) {
out.set(member.getKey(), read);
}
}
return out;
}
private JsonNode readMap(String path, String property, JsonNode value, String valueShape) {
requireType(property, value, JsonNodeType.OBJECT);
ObjectNode out = JsonNodeFactory.instance.objectNode();
for (Map.Entry<String, JsonNode> entry : value.properties()) {
JsonNode read = read(path + "/" + entry.getKey(), entry.getKey(), entry.getValue(), valueShape);
if (read != null) {
out.set(entry.getKey(), read);
}
}
return out;
}
private JsonNode readList(String path, String property, JsonNode value, String itemShape) {
requireType(property, value, JsonNodeType.ARRAY);
ArrayNode out = JsonNodeFactory.instance.arrayNode();
for (int i = 0; i < value.size(); i++) {
JsonNode read = read(path + "/" + i, String.valueOf(i), value.get(i), itemShape);
if (read != null) {
out.add(read);
}
}
return out;
}
/**
* A literal list keeps its blank entries where the template put them, as CloudFormation
* passes it on, and an item that is an object or a list is refused by its index, as for any
* string; any other value is read as {@link CfnPropertyTypes#readStringList} says.
*/
private JsonNode readStringList(String property, JsonNode raw) {
List<String> values;
if (raw.isArray()) {
for (int i = 0; i < raw.size(); i++) {
JsonNode item = raw.get(i);
if (item.isContainerNode() && !CloudFormationTemplateEngine.callsIntrinsic(item)) {
throw templateMismatch(String.valueOf(i), "String", containerName(item));
}
}
values = engine.resolveLiteralList(raw);
} else {
values = CfnPropertyTypes.readStringList(property, raw, engine);
}
if (values == null) {
return null;
}
ArrayNode out = JsonNodeFactory.instance.arrayNode();
values.forEach(out::add);
return out;
}
private static JsonNode readString(String property, JsonNode value) {
if (value.isContainerNode()) {
throw templateMismatch(property, "String", containerName(value));
}
return value.isTextual() ? value : TextNode.valueOf(value.asText());
}
private JsonNode readInteger(String path, String property, JsonNode value) {
@Override
JsonNode readInteger(String path, String property, JsonNode value) {
String text = value.isIntegralNumber() ? value.bigIntegerValue().toString() : value.asText();
if (value.isContainerNode() || value.isBoolean() || !WHOLE_NUMBER.matcher(text).matches()) {
throw templateMismatch(property, "Integer", scalarName(value));
@@ -249,7 +337,8 @@ final class CfnPropertyTypes {
return IntNode.valueOf(number.intValue());
}
private JsonNode readBoolean(String path, String property, JsonNode value) {
@Override
JsonNode readBoolean(String path, String property, JsonNode value) {
if (value.isContainerNode()) {
throw templateMismatch(property, "Boolean", containerName(value));
}
@@ -263,12 +352,186 @@ final class CfnPropertyTypes {
private void recordModelFailure(String path, String expected, String hint) {
if (modelFailure == null) {
modelFailure = new AwsException("InvalidRequest", "Model validation failed (#/" + path
+ ": expected type: " + expected + ", found: String" + hint + ")", 400);
modelFailure = modelValidation("#/" + path + ": expected type: " + expected + ", found: String"
+ hint + ")");
}
}
}
/**
* Reads a resource's properties as its handler does when CloudFormation hands them over without
* template validation, every scalar as text, as it does an {@code AWS::ECS::TaskDefinition}'s
* (measured in eu-west-1, 2026-10-19). The handler converts each value to the type its model
* declares: an integer is a sign and digits once trimmed, within 32 bits, and a boolean is true
* or false in lower, upper or title case once trimmed.
*
* <p>When a value does not convert, or an object, a list and a scalar stand for one another, the
* resource fails with every violation of the unconverted model, where every scalar is a String,
* so an integer or a boolean that converts is listed too: "Model validation failed
* (#/ContainerDefinitions/0/Memory: expected type: Integer, found: String. This may occur ...
* \n#/ContainerDefinitions/0/LinuxParameters/Capabilities/Add: expected type: JSONArray, found:
* String)". At each object its missing required members come first, then its members in the
* schema's order. When every value converts, only the required members the converted model lacks
* fail it, grouped where their paths meet as the schema validator groups them: "Model validation
* failed (#/ContainerDefinitions: 2 schema violations found)\n#/ContainerDefinitions/0: required
* key [Name] not found (#/ContainerDefinitions/0)\n...".
*/
static final class HandlerReader extends ShapeWalk {
private final List<Violation> violations = new ArrayList<>();
private boolean unconverted;
HandlerReader(CloudFormationTemplateEngine engine) {
this(engine, Holder.MODEL);
}
HandlerReader(CloudFormationTemplateEngine engine, RequestShapeModel model) {
super(engine, model);
}
/** The properties {@code props} of a {@code resourceType}, resolved and converted as its handler reads them. */
JsonNode read(String resourceType, JsonNode props) {
String shape = model.operations().get(resourceType);
if (shape == null) {
throw notVendored(resourceType);
}
JsonNode raw = props == null || props.isNull() ? JsonNodeFactory.instance.objectNode() : props;
JsonNode read = read("", "", engine.omitNoValue(raw), shape);
if (unconverted) {
throw modelValidation(String.join("\n", violations.stream().map(Violation::text).toList()) + ")");
}
List<Violation> missing = violations.stream().filter(Violation::required).toList();
if (!missing.isEmpty()) {
throw modelValidation(grouped(missing));
}
return read;
}
@Override
void mismatch(String path, String property, String expected, String found) {
record(new Violation(path, "expected type: " + expected + ", found: " + found, false), false);
}
@Override
JsonNode readInteger(String path, String property, JsonNode value) {
if (value.isContainerNode()) {
mismatch(path, property, "Integer", containerName(value));
return null;
}
String text = value.asText().trim();
Integer number = null;
if (SIGNED_WHOLE_NUMBER.matcher(text).matches()) {
try {
number = Integer.parseInt(text);
} catch (NumberFormatException beyond32Bits) {
number = null;
}
}
record(new Violation(path, "expected type: Integer, found: String" + INTEGER_RANGE_HINT, false),
number != null);
return number == null ? value : IntNode.valueOf(number);
}
@Override
JsonNode readBoolean(String path, String property, JsonNode value) {
if (value.isContainerNode()) {
mismatch(path, property, "Boolean", containerName(value));
return null;
}
String text = value.asText().trim();
Boolean flag = TRUE_TEXT.contains(text) ? Boolean.TRUE : FALSE_TEXT.contains(text) ? Boolean.FALSE : null;
record(new Violation(path, "expected type: Boolean, found: String", false), flag != null);
return flag == null ? value : BooleanNode.valueOf(flag);
}
@Override
void checkRequired(String path, JsonNode value, Shape shape) {
for (String member : shape.required()) {
if (!value.has(member)) {
record(new Violation(path, "required key [" + member + "] not found", true), true);
}
}
}
/** The members the shape declares in the schema's order, which the handler reports in, then the others. */
@Override
Iterable<Map.Entry<String, JsonNode>> members(JsonNode value, Shape shape) {
Map<String, JsonNode> ordered = new LinkedHashMap<>();
shape.members().keySet().forEach(name -> {
if (value.has(name)) {
ordered.put(name, value.get(name));
}
});
value.properties().forEach(member -> ordered.putIfAbsent(member.getKey(), member.getValue()));
return ordered.entrySet();
}
private void record(Violation violation, boolean converts) {
violations.add(violation);
unconverted |= !converts;
}
/**
* The violations {@code leaves}, one or several, as the schema validator reports them: several
* are counted where their paths meet, and listed by that node's direct causes, a group of them
* under one member counted where its own paths meet.
*/
private static String grouped(List<Violation> leaves) {
if (leaves.size() == 1) {
return leaves.getFirst().text() + ")";
}
String meeting = meeting(leaves);
StringBuilder message = new StringBuilder(pointer(meeting) + ": " + leaves.size()
+ " schema violations found)");
Map<String, List<Violation>> causes = new LinkedHashMap<>();
for (Violation leaf : leaves) {
String rest = leaf.path().equals(meeting) ? null
: leaf.path().substring(meeting.isEmpty() ? 0 : meeting.length() + 1);
String cause = rest == null ? "#" + causes.size() : rest.split("/", 2)[0];
causes.computeIfAbsent(cause, key -> new ArrayList<>()).add(leaf);
}
for (List<Violation> cause : causes.values()) {
String at = cause.size() == 1 ? cause.getFirst().path() : meeting(cause);
String text = cause.size() == 1 ? cause.getFirst().text()
: pointer(at) + ": " + cause.size() + " schema violations found";
message.append('\n').append(text).append(" (").append(pointer(at)).append(')');
}
return message.toString();
}
/** The deepest path every one of {@code violations} lies under. */
private static String meeting(List<Violation> violations) {
String[] common = violations.getFirst().path().split("/");
int length = violations.getFirst().path().isEmpty() ? 0 : common.length;
for (Violation violation : violations) {
String[] segments = violation.path().isEmpty() ? new String[0] : violation.path().split("/");
int shared = 0;
while (shared < Math.min(length, segments.length) && common[shared].equals(segments[shared])) {
shared++;
}
length = shared;
}
return String.join("/", List.of(common).subList(0, length));
}
private static String pointer(String path) {
return path.isEmpty() ? "#" : "#/" + path;
}
/** One violation of the model at {@code path}, a missing required member or a type. */
private record Violation(String path, String message, boolean required) {
String text() {
return pointer(path) + ": " + message;
}
}
}
/** The resource handler's model validation failure; {@code violations} ends with its closing parenthesis. */
private static AwsException modelValidation(String violations) {
return new AwsException("InvalidRequest", "Model validation failed (" + violations, 400);
}
private static AwsException templateMismatch(String property, String expected, String found) {
return new AwsException("ValidationError", "Property [" + property + "] expected type: "
+ expected + ", found: " + found, 400);
@@ -277,7 +540,7 @@ final class CfnPropertyTypes {
private static String containerName(JsonNode value) {
return switch (value.getNodeType()) {
case OBJECT -> "JSONObject";
case ARRAY -> "JSONArray";
case ARRAY -> LIST;
default -> "String";
};
}
@@ -140,15 +140,17 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
/**
* Every property of a task definition is create-only, so an update registers a fresh revision
* under the same family, as CloudFormation does on AWS; the physical id is the new revision's
* ARN, and the displaced revision is deregistered once the stack update commits.
* ARN, and the displaced revision is deregistered once the stack update commits. CloudFormation
* hands the properties to the ECS handler without template validation, and they are read as it
* reads them, failing the resource where its model validation does.
*/
private void provisionTaskDefinition(StackResource r, JsonNode props, ProvisionContext ctx) {
private void provisionTaskDefinition(StackResource r, JsonNode template, ProvisionContext ctx) {
JsonNode props = new CfnPropertyTypes.HandlerReader(ctx.engine()).read(TASK_DEFINITION, template);
String family = ctx.resolveOptional(props, "Family");
if (family == null || family.isBlank()) {
family = ctx.generatePhysicalName(r.getLogicalId(), 255, false);
}
List<ContainerDefinition> containerDefs =
parseContainerDefinitions(props != null ? props.get("ContainerDefinitions") : null, ctx);
List<ContainerDefinition> containerDefs = parseContainerDefinitions(props.get("ContainerDefinitions"), ctx);
NetworkMode networkMode = parseEnum(NetworkMode.class, ctx.resolveOptional(props, "NetworkMode"));
String cpu = ctx.resolveOptional(props, "Cpu");
String memory = ctx.resolveOptional(props, "Memory");