Light, fluffy, and always free - The AWS Local Emulator alternative
fix(cloudformation): read an ECS task definition's properties as the ECS handler does (#6018)
Alessandro Lattaofcb41966a8b1
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CloudFormationEcsTaskDefinitionModelTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CloudFormationEcsTaskDefinitionModelTest.javanew file mode 100644index 0000000000..2f8d79c7ac--- /dev/null+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CloudFormationEcsTaskDefinitionModelTest.java@@ -0,0 +1,113 @@+package com.floci.test;++import org.junit.jupiter.api.AfterAll;+import org.junit.jupiter.api.BeforeAll;+import org.junit.jupiter.api.DisplayName;+import org.junit.jupiter.api.Test;+import software.amazon.awssdk.services.cloudformation.CloudFormationClient;+import software.amazon.awssdk.services.cloudformation.model.StackEvent;+import software.amazon.awssdk.services.ecs.EcsClient;+import software.amazon.awssdk.services.ecs.model.ContainerDefinition;++import java.time.Duration;+import java.util.List;++import static org.assertj.core.api.Assertions.assertThat;++/**+ * An AWS::ECS::TaskDefinition read as the ECS handler reads it, through the CloudFormation SDK+ * client. Measured on AWS (eu-west-1, 2026-10-19): CloudFormation hands the properties over+ * without template validation, every scalar as text; the handler converts "+128" and "False" (a+ * second container, since ECS refuses a task definition without an essential one), and+ * a value it cannot convert fails the resource with every violation of the unconverted model,+ * the Memory it could convert included.+ */+@DisplayName("CloudFormation ECS task definition model")+class CloudFormationEcsTaskDefinitionModelTest {++ private static final Duration DEPLOY_TIMEOUT = Duration.ofSeconds(60);+ private static final String UNCONVERTED_STACK = TestFixtures.uniqueName("compat-cfn-ecs-unconverted");+ private static final String CONVERTED_STACK = TestFixtures.uniqueName("compat-cfn-ecs-converted");+ private static final String 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.";++ private static CloudFormationClient cfn;++ @BeforeAll+ static void setup() {+ cfn = TestFixtures.cloudFormationClient();+ }++ @AfterAll+ static void cleanup() {+ if (cfn != null) {+ // DeleteStack answers for a stack that is gone too, so a failure here is a real one.+ cfn.deleteStack(request -> request.stackName(UNCONVERTED_STACK));+ cfn.deleteStack(request -> request.stackName(CONVERTED_STACK));+ cfn.close();+ }+ }++ @Test+ @DisplayName("a value the handler cannot convert fails the stack with every violation")+ void aValueTheHandlerCannotConvertFailsTheStack() throws InterruptedException {+ cfn.createStack(request -> request.stackName(UNCONVERTED_STACK).templateBody(template(UNCONVERTED_STACK,+ "\"Memory\": 128, \"LinuxParameters\": {\"SharedMemorySize\": \"abc\"}")));+ assertThat(TestFixtures.awaitStackTerminal(cfn, UNCONVERTED_STACK, DEPLOY_TIMEOUT)).isEqualTo("ROLLBACK_COMPLETE");+ assertThat(reasons(UNCONVERTED_STACK)).anyMatch(reason -> reason.contains("Model validation failed"+ + " (#/ContainerDefinitions/0/Memory: expected type: Integer, found: String" + HINT+ + "\n#/ContainerDefinitions/0/LinuxParameters/SharedMemorySize: expected type: Integer, found: String"+ + HINT + ")"));+ }++ @Test+ @DisplayName("values the handler converts are registered converted")+ void valuesTheHandlerConvertsAreRegisteredConverted() throws InterruptedException {+ cfn.createStack(request -> request.stackName(CONVERTED_STACK).templateBody(template(CONVERTED_STACK,+ "\"Memory\": \"+128\"}, {\"Name\": \"side\", \"Image\": \"public.ecr.aws/docker/library/busybox:latest\","+ + " \"Memory\": 64, \"Essential\": \"False\"")));+ assertThat(TestFixtures.awaitStackTerminal(cfn, CONVERTED_STACK, DEPLOY_TIMEOUT)).isEqualTo("CREATE_COMPLETE");++ String taskDefinition = cfn.describeStackResource(request -> request.stackName(CONVERTED_STACK)+ .logicalResourceId("TaskDef")).stackResourceDetail().physicalResourceId();+ try (EcsClient ecs = TestFixtures.ecsClient()) {+ List<ContainerDefinition> containers = ecs.describeTaskDefinition(request -> request+ .taskDefinition(taskDefinition)).taskDefinition().containerDefinitions();+ assertThat(containers).filteredOn(container -> container.name().equals("app"))+ .singleElement().extracting(ContainerDefinition::memory).isEqualTo(128);+ assertThat(containers).filteredOn(container -> container.name().equals("side"))+ .singleElement().extracting(ContainerDefinition::essential).isEqualTo(false);+ }+ }++ private static List<String> reasons(String stackName) {+ return cfn.describeStackEvents(request -> request.stackName(stackName)).stackEvents().stream()+ .map(StackEvent::resourceStatusReason)+ .filter(reason -> reason != null)+ .toList();+ }++ /**+ * A task definition named after the stack, whose first container has {@code members} beside+ * its name and image; {@code members} may close it and open others.+ */+ private static String template(String family, String members) {+ return """+ {+ "Resources": {+ "TaskDef": {+ "Type": "AWS::ECS::TaskDefinition",+ "Properties": {+ "Family": "%s",+ "ContainerDefinitions": [{+ "Name": "app",+ "Image": "public.ecr.aws/docker/library/busybox:latest",+ %s+ }]+ }+ }+ }+ }+ """.formatted(family, members);+ }+}diff --git a/docs/services/cloudformation.md b/docs/services/cloudformation.mdindex f907372ed2..da22344b85 100644--- a/docs/services/cloudformation.md+++ b/docs/services/cloudformation.md@@ -540,6 +540,34 @@ Dynamic-reference expansion is currently scoped to these RDS credential propertiproperty answers `GetBucketOwnershipControls` with `OwnershipControlsNotFoundError`, where AWSreports its default, `BucketOwnerEnforced`.+## ECS task definitions++CloudFormation hands an `AWS::ECS::TaskDefinition`'s properties to the ECS resource handler+without template validation, every value as text, and the handler converts each to the type the+resource schema declares (measured). Floci reads them the same way, before anything is registered:++- An integer is a sign and digits once trimmed, within 32 bits (`"+128"`, `" 128"` and `"0128"`+ are 128), and a boolean is `true` or `false` in lower, upper or title case once trimmed+ (`"True"`, `" true"`). A number where text is expected is its text.+- A value that does not convert (`"abc"`, `4.5` or `true` for an integer, `"yes"`, `"tRuE"` or+ `"1"` for a boolean), an object or a list where a scalar is expected, and a scalar where an object+ or a list is expected fail the resource with every violation of the unconverted model, where+ every scalar is text, 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 when a numeric value exceeds 32-bit integer max (2147483647). Consider using+ 'number' type or ensure value fits in integer range.` and, on the next line,+ `#/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, the required members the model lacks fail it:+ `Model validation failed (#/ContainerDefinitions/0: required key [Image] not found)`. Several are+ counted where their paths meet, `Model validation failed (#/ContainerDefinitions: 2 schema+ violations found)`, with a line for each below it.+- A `Ref` to a `CommaDelimitedList` parameter is a list, and a `Ref` to a `String` parameter is text.+- The schema's other constraints (allowed values, patterns, bounds) are not checked. AWS also+ records a warning event for a value that it does not convert itself and the handler does+ (`" 128"`, `"0128"`, `" true"`); Floci does not.+## Account-Aware ProvisioningResources provisioned by `CreateStack` / `UpdateStack` land in the **caller's account** namespacediff --git a/src/main/java/io/github/hectorvent/floci/core/common/RequestShapeModel.java b/src/main/java/io/github/hectorvent/floci/core/common/RequestShapeModel.javaindex 838434b549..85864fd316 100644--- a/src/main/java/io/github/hectorvent/floci/core/common/RequestShapeModel.java+++ b/src/main/java/io/github/hectorvent/floci/core/common/RequestShapeModel.java@@ -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, ShapMap<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));}diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnPropertyTypes.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnPropertyTypes.javaindex 0e960fde49..74995811ef 100644--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnPropertyTypes.java+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnPropertyTypes.java@@ -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,58 +123,51 @@ 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;}/**- * 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.+ * 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.*/- static final class Reader {+ private abstract static class ShapeWalk {- private final CloudFormationTemplateEngine engine;- private final RequestShapeModel model;- private AwsException modelFailure;-- Reader(CloudFormationTemplateEngine engine) {- this(engine, Holder.MODEL);- }+ final CloudFormationTemplateEngine engine;+ final RequestShapeModel model;- Reader(CloudFormationTemplateEngine engine, RequestShapeModel model) {+ ShapeWalk(CloudFormationTemplateEngine engine, RequestShapeModel model) {this.engine = engine;this.model = model;}- /**- * The template value {@code raw}, at {@code path} in the resource's properties, read as the- * shape {@code shapeName}; null when it is absent or {@code AWS::NoValue}.- */- JsonNode read(String path, JsonNode raw, String shapeName) {- return read(path, path.substring(path.lastIndexOf('/') + 1), engine.omitNoValue(raw), shapeName);+ /** 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) {}- /** Throws the first model validation failure found by {@link #read}, if any. */- void finish() {- if (modelFailure != null) {- throw modelFailure;- }+ /** 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();}- private JsonNode read(String path, String property, JsonNode raw, String shapeName) {+ 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);+ return readStringList(path, property, raw);}JsonNode value = raw.isContainerNode() && !CloudFormationTemplateEngine.callsIntrinsic(raw)? raw : engine.resolveNode(raw);@@ -154,23 +175,34 @@ final class CfnPropertyTypes {return null;}return switch (shape.type()) {- case "structure" -> readObject(path, property, value, shape.members());+ 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(property, value);+ 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 JsonNode readObject(String path, String property, JsonNode value, Map<String, String> members) {- requireType(property, value, JsonNodeType.OBJECT);+ 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 : value.properties()) {- String memberShape = members.get(member.getKey());+ 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(path + "/" + member.getKey(), member.getKey(), member.getValue(), memberShape);+ : read(child(path, member.getKey()), member.getKey(), member.getValue(), memberShape);if (read != null) {out.set(member.getKey(), read);}@@ -179,10 +211,12 @@ final class CfnPropertyTypes {}private JsonNode readMap(String path, String property, JsonNode value, String valueShape) {- requireType(property, value, JsonNodeType.OBJECT);+ 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(path + "/" + entry.getKey(), entry.getKey(), entry.getValue(), valueShape);+ JsonNode read = read(child(path, entry.getKey()), entry.getKey(), entry.getValue(), valueShape);if (read != null) {out.set(entry.getKey(), read);}@@ -191,10 +225,12 @@ final class CfnPropertyTypes {}private JsonNode readList(String path, String property, JsonNode value, String itemShape) {- requireType(property, value, JsonNodeType.ARRAY);+ 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(path + "/" + i, String.valueOf(i), value.get(i), itemShape);+ JsonNode read = read(child(path, String.valueOf(i)), String.valueOf(i), value.get(i), itemShape);if (read != null) {out.add(read);}@@ -207,18 +243,24 @@ final class CfnPropertyTypes {* 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) {+ 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)) {- throw templateMismatch(String.valueOf(i), "String", containerName(item));+ mismatch(child(path, String.valueOf(i)), String.valueOf(i), "String", containerName(item));+ strings = false;}}- values = engine.resolveLiteralList(raw);+ values = strings ? engine.resolveLiteralList(raw) : null;} else {- values = CfnPropertyTypes.readStringList(property, raw, engine);+ 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;@@ -228,14 +270,60 @@ final class CfnPropertyTypes {return out;}- private static JsonNode readString(String property, JsonNode value) {+ private JsonNode readString(String path, String property, JsonNode value) {if (value.isContainerNode()) {- throw templateMismatch(property, "String", containerName(value));+ mismatch(path, property, "String", containerName(value));+ return null;}return value.isTextual() ? value : TextNode.valueOf(value.asText());}- private JsonNode readInteger(String path, String property, JsonNode value) {+ 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.+ * 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 extends ShapeWalk {++ private AwsException modelFailure;++ Reader(CloudFormationTemplateEngine engine) {+ this(engine, Holder.MODEL);+ }++ Reader(CloudFormationTemplateEngine engine, RequestShapeModel model) {+ super(engine, model);+ }++ /**+ * The template value {@code raw}, at {@code path} in the resource's properties, read as the+ * shape {@code shapeName}; null when it is absent or {@code AWS::NoValue}.+ */+ JsonNode read(String path, JsonNode raw, String shapeName) {+ return read(path, path.substring(path.lastIndexOf('/') + 1), engine.omitNoValue(raw), shapeName);+ }++ /** Throws the first model validation failure found by {@link #read}, if any. */+ void finish() {+ if (modelFailure != null) {+ throw modelFailure;+ }+ }++ @Override+ void mismatch(String path, String property, String expected, String found) {+ throw templateMismatch(property, expected, found);+ }++ @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,10 +352,184 @@ 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) {@@ -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";};}diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EcsCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EcsCfnProvisioner.javaindex 9689af0235..603bf1ce28 100644--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EcsCfnProvisioner.java+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EcsCfnProvisioner.java@@ -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");diff --git a/src/main/resources/aws/cfn-property-types.json b/src/main/resources/aws/cfn-property-types.jsonindex 4ecea6c7c5..726d7581fd 100644--- a/src/main/resources/aws/cfn-property-types.json+++ b/src/main/resources/aws/cfn-property-types.json@@ -7,6 +7,7 @@},"operations": {"AWS::AutoScaling::LaunchConfiguration": "AWS::AutoScaling::LaunchConfiguration",+ "AWS::ECS::TaskDefinition": "AWS::ECS::TaskDefinition","AWS::Events::Rule": "AWS::Events::Rule","AWS::Lambda::Function": "AWS::Lambda::Function","AWS::Lambda::LayerVersion": "AWS::Lambda::LayerVersion"@@ -34,7 +35,11 @@"InstanceType": "String","RamDiskId": "String","InstanceMonitoring": "Boolean"- }+ },+ "required": [+ "ImageId",+ "InstanceType"+ ]},"AWS::AutoScaling::LaunchConfiguration.BlockDeviceMappings": {"type": "list",@@ -67,7 +72,10 @@"NoDevice": "Boolean","VirtualName": "String","DeviceName": "String"- }+ },+ "required": [+ "DeviceName"+ ]},"AWS::AutoScaling::LaunchConfiguration/MetadataOptions": {"type": "structure",@@ -77,6 +85,543 @@"HttpEndpoint": "String"}},+ "AWS::ECS::TaskDefinition": {+ "type": "structure",+ "members": {+ "TaskRoleArn": "String",+ "IpcMode": "String",+ "InferenceAccelerators": "AWS::ECS::TaskDefinition.InferenceAccelerators",+ "Memory": "String",+ "PlacementConstraints": "AWS::ECS::TaskDefinition.PlacementConstraints",+ "Cpu": "String",+ "RequiresCompatibilities": "AWS::ECS::TaskDefinition.RequiresCompatibilities",+ "NetworkMode": "String",+ "PidMode": "String",+ "EnableFaultInjection": "Boolean",+ "ExecutionRoleArn": "String",+ "RuntimePlatform": "AWS::ECS::TaskDefinition/RuntimePlatform",+ "ProxyConfiguration": "AWS::ECS::TaskDefinition/ProxyConfiguration",+ "Volumes": "AWS::ECS::TaskDefinition.Volumes",+ "ContainerDefinitions": "AWS::ECS::TaskDefinition.ContainerDefinitions",+ "Family": "String",+ "EphemeralStorage": "AWS::ECS::TaskDefinition/EphemeralStorage",+ "Tags": "AWS::ECS::TaskDefinition.Tags",+ "TaskDefinitionArn": "String"+ }+ },+ "AWS::ECS::TaskDefinition.ContainerDefinitions": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/ContainerDefinition"+ },+ "AWS::ECS::TaskDefinition.InferenceAccelerators": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/InferenceAccelerator"+ },+ "AWS::ECS::TaskDefinition.PlacementConstraints": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/TaskDefinitionPlacementConstraint"+ },+ "AWS::ECS::TaskDefinition.RequiresCompatibilities": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition.Tags": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/Tag"+ },+ "AWS::ECS::TaskDefinition.Volumes": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/Volume"+ },+ "AWS::ECS::TaskDefinition/AuthorizationConfig": {+ "type": "structure",+ "members": {+ "IAM": "String",+ "AccessPointId": "String"+ }+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition": {+ "type": "structure",+ "members": {+ "User": "String",+ "Secrets": "AWS::ECS::TaskDefinition/ContainerDefinition.Secrets",+ "Memory": "Integer",+ "Privileged": "Boolean",+ "HealthCheck": "AWS::ECS::TaskDefinition/HealthCheck",+ "StartTimeout": "Integer",+ "VolumesFrom": "AWS::ECS::TaskDefinition/ContainerDefinition.VolumesFrom",+ "Cpu": "Integer",+ "EntryPoint": "AWS::ECS::TaskDefinition/ContainerDefinition.EntryPoint",+ "DnsServers": "AWS::ECS::TaskDefinition/ContainerDefinition.DnsServers",+ "ReadonlyRootFilesystem": "Boolean",+ "Image": "String",+ "Essential": "Boolean",+ "LogConfiguration": "AWS::ECS::TaskDefinition/LogConfiguration",+ "ResourceRequirements": "AWS::ECS::TaskDefinition/ContainerDefinition.ResourceRequirements",+ "EnvironmentFiles": "AWS::ECS::TaskDefinition/ContainerDefinition.EnvironmentFiles",+ "Name": "String",+ "FirelensConfiguration": "AWS::ECS::TaskDefinition/FirelensConfiguration",+ "DockerSecurityOptions": "AWS::ECS::TaskDefinition/ContainerDefinition.DockerSecurityOptions",+ "SystemControls": "AWS::ECS::TaskDefinition/ContainerDefinition.SystemControls",+ "Interactive": "Boolean",+ "DnsSearchDomains": "AWS::ECS::TaskDefinition/ContainerDefinition.DnsSearchDomains",+ "CredentialSpecs": "AWS::ECS::TaskDefinition/ContainerDefinition.CredentialSpecs",+ "Ulimits": "AWS::ECS::TaskDefinition/ContainerDefinition.Ulimits",+ "StopTimeout": "Integer",+ "WorkingDirectory": "String",+ "MemoryReservation": "Integer",+ "RepositoryCredentials": "AWS::ECS::TaskDefinition/RepositoryCredentials",+ "ExtraHosts": "AWS::ECS::TaskDefinition/ContainerDefinition.ExtraHosts",+ "Hostname": "String",+ "LinuxParameters": "AWS::ECS::TaskDefinition/LinuxParameters",+ "VersionConsistency": "String",+ "RestartPolicy": "AWS::ECS::TaskDefinition/RestartPolicy",+ "DisableNetworking": "Boolean",+ "PseudoTerminal": "Boolean",+ "MountPoints": "AWS::ECS::TaskDefinition/ContainerDefinition.MountPoints",+ "DependsOn": "AWS::ECS::TaskDefinition/ContainerDefinition.DependsOn",+ "DockerLabels": "AWS::ECS::TaskDefinition/ContainerDefinition.DockerLabels",+ "PortMappings": "AWS::ECS::TaskDefinition/ContainerDefinition.PortMappings",+ "Command": "AWS::ECS::TaskDefinition/ContainerDefinition.Command",+ "Environment": "AWS::ECS::TaskDefinition/ContainerDefinition.Environment",+ "Links": "AWS::ECS::TaskDefinition/ContainerDefinition.Links"+ },+ "required": [+ "Name",+ "Image"+ ]+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.Command": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.CredentialSpecs": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.DependsOn": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/ContainerDependency"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.DnsSearchDomains": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.DnsServers": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.DockerLabels": {+ "type": "map",+ "value": "String"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.DockerSecurityOptions": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.EntryPoint": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.Environment": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/KeyValuePair"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.EnvironmentFiles": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/EnvironmentFile"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.ExtraHosts": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/HostEntry"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.Links": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.MountPoints": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/MountPoint"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.PortMappings": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/PortMapping"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.ResourceRequirements": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/ResourceRequirement"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.Secrets": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/Secret"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.SystemControls": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/SystemControl"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.Ulimits": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/Ulimit"+ },+ "AWS::ECS::TaskDefinition/ContainerDefinition.VolumesFrom": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/VolumeFrom"+ },+ "AWS::ECS::TaskDefinition/ContainerDependency": {+ "type": "structure",+ "members": {+ "Condition": "String",+ "ContainerName": "String"+ }+ },+ "AWS::ECS::TaskDefinition/Device": {+ "type": "structure",+ "members": {+ "HostPath": "String",+ "Permissions": "AWS::ECS::TaskDefinition/Device.Permissions",+ "ContainerPath": "String"+ }+ },+ "AWS::ECS::TaskDefinition/Device.Permissions": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition/DockerVolumeConfiguration": {+ "type": "structure",+ "members": {+ "DriverOpts": "AWS::ECS::TaskDefinition/DockerVolumeConfiguration.DriverOpts",+ "Scope": "String",+ "Autoprovision": "Boolean",+ "Driver": "String",+ "Labels": "AWS::ECS::TaskDefinition/DockerVolumeConfiguration.Labels"+ }+ },+ "AWS::ECS::TaskDefinition/DockerVolumeConfiguration.DriverOpts": {+ "type": "map",+ "value": "String"+ },+ "AWS::ECS::TaskDefinition/DockerVolumeConfiguration.Labels": {+ "type": "map",+ "value": "String"+ },+ "AWS::ECS::TaskDefinition/EFSVolumeConfiguration": {+ "type": "structure",+ "members": {+ "FilesystemId": "String",+ "TransitEncryption": "String",+ "AuthorizationConfig": "AWS::ECS::TaskDefinition/AuthorizationConfig",+ "RootDirectory": "String",+ "TransitEncryptionPort": "Integer"+ },+ "required": [+ "FilesystemId"+ ]+ },+ "AWS::ECS::TaskDefinition/EnvironmentFile": {+ "type": "structure",+ "members": {+ "Type": "String",+ "Value": "String"+ }+ },+ "AWS::ECS::TaskDefinition/EphemeralStorage": {+ "type": "structure",+ "members": {+ "SizeInGiB": "Integer"+ }+ },+ "AWS::ECS::TaskDefinition/FSxAuthorizationConfig": {+ "type": "structure",+ "members": {+ "CredentialsParameter": "String",+ "Domain": "String"+ },+ "required": [+ "CredentialsParameter",+ "Domain"+ ]+ },+ "AWS::ECS::TaskDefinition/FSxWindowsFileServerVolumeConfiguration": {+ "type": "structure",+ "members": {+ "AuthorizationConfig": "AWS::ECS::TaskDefinition/FSxAuthorizationConfig",+ "FileSystemId": "String",+ "RootDirectory": "String"+ },+ "required": [+ "FileSystemId",+ "RootDirectory"+ ]+ },+ "AWS::ECS::TaskDefinition/FirelensConfiguration": {+ "type": "structure",+ "members": {+ "Options": "AWS::ECS::TaskDefinition/FirelensConfiguration.Options",+ "Type": "String"+ }+ },+ "AWS::ECS::TaskDefinition/FirelensConfiguration.Options": {+ "type": "map",+ "value": "String"+ },+ "AWS::ECS::TaskDefinition/HealthCheck": {+ "type": "structure",+ "members": {+ "Command": "AWS::ECS::TaskDefinition/HealthCheck.Command",+ "Timeout": "Integer",+ "Retries": "Integer",+ "Interval": "Integer",+ "StartPeriod": "Integer"+ }+ },+ "AWS::ECS::TaskDefinition/HealthCheck.Command": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition/HostEntry": {+ "type": "structure",+ "members": {+ "Hostname": "String",+ "IpAddress": "String"+ }+ },+ "AWS::ECS::TaskDefinition/HostVolumeProperties": {+ "type": "structure",+ "members": {+ "SourcePath": "String"+ }+ },+ "AWS::ECS::TaskDefinition/InferenceAccelerator": {+ "type": "structure",+ "members": {+ "DeviceType": "String",+ "DeviceName": "String"+ }+ },+ "AWS::ECS::TaskDefinition/KernelCapabilities": {+ "type": "structure",+ "members": {+ "Add": "AWS::ECS::TaskDefinition/KernelCapabilities.Add",+ "Drop": "AWS::ECS::TaskDefinition/KernelCapabilities.Drop"+ }+ },+ "AWS::ECS::TaskDefinition/KernelCapabilities.Add": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition/KernelCapabilities.Drop": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition/KeyValuePair": {+ "type": "structure",+ "members": {+ "Value": "String",+ "Name": "String"+ }+ },+ "AWS::ECS::TaskDefinition/LinuxParameters": {+ "type": "structure",+ "members": {+ "Capabilities": "AWS::ECS::TaskDefinition/KernelCapabilities",+ "Swappiness": "Integer",+ "Tmpfs": "AWS::ECS::TaskDefinition/LinuxParameters.Tmpfs",+ "SharedMemorySize": "Integer",+ "Devices": "AWS::ECS::TaskDefinition/LinuxParameters.Devices",+ "InitProcessEnabled": "Boolean",+ "MaxSwap": "Integer"+ }+ },+ "AWS::ECS::TaskDefinition/LinuxParameters.Devices": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/Device"+ },+ "AWS::ECS::TaskDefinition/LinuxParameters.Tmpfs": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/Tmpfs"+ },+ "AWS::ECS::TaskDefinition/LogConfiguration": {+ "type": "structure",+ "members": {+ "SecretOptions": "AWS::ECS::TaskDefinition/LogConfiguration.SecretOptions",+ "Options": "AWS::ECS::TaskDefinition/LogConfiguration.Options",+ "LogDriver": "String"+ },+ "required": [+ "LogDriver"+ ]+ },+ "AWS::ECS::TaskDefinition/LogConfiguration.Options": {+ "type": "map",+ "value": "String"+ },+ "AWS::ECS::TaskDefinition/LogConfiguration.SecretOptions": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/Secret"+ },+ "AWS::ECS::TaskDefinition/MountPoint": {+ "type": "structure",+ "members": {+ "ReadOnly": "Boolean",+ "SourceVolume": "String",+ "ContainerPath": "String"+ }+ },+ "AWS::ECS::TaskDefinition/PortMapping": {+ "type": "structure",+ "members": {+ "AppProtocol": "String",+ "ContainerPortRange": "String",+ "HostPort": "Integer",+ "ContainerPort": "Integer",+ "Protocol": "String",+ "Name": "String"+ }+ },+ "AWS::ECS::TaskDefinition/ProxyConfiguration": {+ "type": "structure",+ "members": {+ "ProxyConfigurationProperties": "AWS::ECS::TaskDefinition/ProxyConfiguration.ProxyConfigurationProperties",+ "Type": "String",+ "ContainerName": "String"+ },+ "required": [+ "ContainerName"+ ]+ },+ "AWS::ECS::TaskDefinition/ProxyConfiguration.ProxyConfigurationProperties": {+ "type": "list",+ "member": "AWS::ECS::TaskDefinition/KeyValuePair"+ },+ "AWS::ECS::TaskDefinition/RepositoryCredentials": {+ "type": "structure",+ "members": {+ "CredentialsParameter": "String"+ }+ },+ "AWS::ECS::TaskDefinition/ResourceRequirement": {+ "type": "structure",+ "members": {+ "Type": "String",+ "Value": "String"+ },+ "required": [+ "Type"+ ]+ },+ "AWS::ECS::TaskDefinition/RestartPolicy": {+ "type": "structure",+ "members": {+ "IgnoredExitCodes": "AWS::ECS::TaskDefinition/RestartPolicy.IgnoredExitCodes",+ "RestartAttemptPeriod": "Integer",+ "Enabled": "Boolean"+ }+ },+ "AWS::ECS::TaskDefinition/RestartPolicy.IgnoredExitCodes": {+ "type": "list",+ "member": "Integer"+ },+ "AWS::ECS::TaskDefinition/RuntimePlatform": {+ "type": "structure",+ "members": {+ "OperatingSystemFamily": "String",+ "CpuArchitecture": "String"+ }+ },+ "AWS::ECS::TaskDefinition/S3FilesVolumeConfiguration": {+ "type": "structure",+ "members": {+ "FileSystemArn": "String",+ "AccessPointArn": "String",+ "RootDirectory": "String",+ "TransitEncryptionPort": "Integer"+ },+ "required": [+ "FileSystemArn"+ ]+ },+ "AWS::ECS::TaskDefinition/Secret": {+ "type": "structure",+ "members": {+ "ValueFrom": "String",+ "Name": "String"+ },+ "required": [+ "Name",+ "ValueFrom"+ ]+ },+ "AWS::ECS::TaskDefinition/SystemControl": {+ "type": "structure",+ "members": {+ "Value": "String",+ "Namespace": "String"+ }+ },+ "AWS::ECS::TaskDefinition/Tag": {+ "type": "structure",+ "members": {+ "Value": "String",+ "Key": "String"+ }+ },+ "AWS::ECS::TaskDefinition/TaskDefinitionPlacementConstraint": {+ "type": "structure",+ "members": {+ "Type": "String",+ "Expression": "String"+ },+ "required": [+ "Type"+ ]+ },+ "AWS::ECS::TaskDefinition/Tmpfs": {+ "type": "structure",+ "members": {+ "Size": "Integer",+ "ContainerPath": "String",+ "MountOptions": "AWS::ECS::TaskDefinition/Tmpfs.MountOptions"+ },+ "required": [+ "Size"+ ]+ },+ "AWS::ECS::TaskDefinition/Tmpfs.MountOptions": {+ "type": "list",+ "member": "String"+ },+ "AWS::ECS::TaskDefinition/Ulimit": {+ "type": "structure",+ "members": {+ "SoftLimit": "Integer",+ "HardLimit": "Integer",+ "Name": "String"+ },+ "required": [+ "HardLimit",+ "Name",+ "SoftLimit"+ ]+ },+ "AWS::ECS::TaskDefinition/Volume": {+ "type": "structure",+ "members": {+ "EFSVolumeConfiguration": "AWS::ECS::TaskDefinition/EFSVolumeConfiguration",+ "S3FilesVolumeConfiguration": "AWS::ECS::TaskDefinition/S3FilesVolumeConfiguration",+ "Host": "AWS::ECS::TaskDefinition/HostVolumeProperties",+ "ConfiguredAtLaunch": "Boolean",+ "DockerVolumeConfiguration": "AWS::ECS::TaskDefinition/DockerVolumeConfiguration",+ "FSxWindowsFileServerVolumeConfiguration": "AWS::ECS::TaskDefinition/FSxWindowsFileServerVolumeConfiguration",+ "Name": "String"+ }+ },+ "AWS::ECS::TaskDefinition/VolumeFrom": {+ "type": "structure",+ "members": {+ "ReadOnly": "Boolean",+ "SourceContainer": "String"+ }+ },"AWS::Events::Rule": {"type": "structure","members": {@@ -105,7 +650,10 @@"type": "structure","members": {"GraphQLOperation": "String"- }+ },+ "required": [+ "GraphQLOperation"+ ]},"AWS::Events::Rule/AwsVpcConfiguration": {"type": "structure",@@ -113,7 +661,10 @@"SecurityGroups": "AWS::Events::Rule/AwsVpcConfiguration.SecurityGroups","Subnets": "AWS::Events::Rule/AwsVpcConfiguration.Subnets","AssignPublicIp": "String"- }+ },+ "required": [+ "Subnets"+ ]},"AWS::Events::Rule/AwsVpcConfiguration.SecurityGroups": {"type": "list",@@ -136,7 +687,11 @@"JobName": "String","RetryStrategy": "AWS::Events::Rule/BatchRetryStrategy","JobDefinition": "String"- }+ },+ "required": [+ "JobName",+ "JobDefinition"+ ]},"AWS::Events::Rule/BatchRetryStrategy": {"type": "structure",@@ -150,7 +705,10 @@"CapacityProvider": "String","Base": "Integer","Weight": "Integer"- }+ },+ "required": [+ "CapacityProvider"+ ]},"AWS::Events::Rule/DeadLetterConfig": {"type": "structure",@@ -175,7 +733,10 @@"TagList": "AWS::Events::Rule/EcsParameters.TagList","NetworkConfiguration": "AWS::Events::Rule/NetworkConfiguration","TaskDefinitionArn": "String"- }+ },+ "required": [+ "TaskDefinitionArn"+ ]},"AWS::Events::Rule/EcsParameters.CapacityProviderStrategy": {"type": "list",@@ -218,7 +779,10 @@"members": {"InputPathsMap": "AWS::Events::Rule/InputTransformer.InputPathsMap","InputTemplate": "String"- }+ },+ "required": [+ "InputTemplate"+ ]},"AWS::Events::Rule/InputTransformer.InputPathsMap": {"type": "map",@@ -228,7 +792,10 @@"type": "structure","members": {"PartitionKeyPath": "String"- }+ },+ "required": [+ "PartitionKeyPath"+ ]},"AWS::Events::Rule/NetworkConfiguration": {"type": "structure",@@ -260,7 +827,10 @@"DbUser": "String","Sql": "String","WithEvent": "Boolean"- }+ },+ "required": [+ "Database"+ ]},"AWS::Events::Rule/RedshiftDataParameters.Sqls": {"type": "list",@@ -277,7 +847,10 @@"type": "structure","members": {"RunCommandTargets": "AWS::Events::Rule/RunCommandParameters.RunCommandTargets"- }+ },+ "required": [+ "RunCommandTargets"+ ]},"AWS::Events::Rule/RunCommandParameters.RunCommandTargets": {"type": "list",@@ -288,7 +861,11 @@"members": {"Values": "AWS::Events::Rule/RunCommandTarget.Values","Key": "String"- }+ },+ "required": [+ "Values",+ "Key"+ ]},"AWS::Events::Rule/RunCommandTarget.Values": {"type": "list",@@ -299,7 +876,11 @@"members": {"Value": "String","Name": "String"- }+ },+ "required": [+ "Value",+ "Name"+ ]},"AWS::Events::Rule/SageMakerPipelineParameters": {"type": "structure",@@ -315,7 +896,10 @@"type": "structure","members": {"MessageGroupId": "String"- }+ },+ "required": [+ "MessageGroupId"+ ]},"AWS::Events::Rule/Tag": {"type": "structure",@@ -344,7 +928,11 @@"Arn": "String","SageMakerPipelineParameters": "AWS::Events::Rule/SageMakerPipelineParameters","RetryPolicy": "AWS::Events::Rule/RetryPolicy"- }+ },+ "required": [+ "Id",+ "Arn"+ ]},"AWS::Lambda::Function": {"type": "structure",@@ -382,7 +970,11 @@"Arn": "String","EphemeralStorage": "AWS::Lambda::Function/EphemeralStorage","Architectures": "AWS::Lambda::Function.Architectures"- }+ },+ "required": [+ "Code",+ "Role"+ ]},"AWS::Lambda::Function.Architectures": {"type": "list",@@ -404,7 +996,10 @@"type": "structure","members": {"LambdaManagedInstancesCapacityProviderConfig": "AWS::Lambda::Function/LambdaManagedInstancesCapacityProviderConfig"- }+ },+ "required": [+ "LambdaManagedInstancesCapacityProviderConfig"+ ]},"AWS::Lambda::Function/Code": {"type": "structure",@@ -430,7 +1025,10 @@"KMSKeyArn": "String","ExecutionTimeout": "Integer","RetentionPeriodInDays": "Integer"- }+ },+ "required": [+ "ExecutionTimeout"+ ]},"AWS::Lambda::Function/Environment": {"type": "structure",@@ -446,7 +1044,10 @@"type": "structure","members": {"Size": "Integer"- }+ },+ "required": [+ "Size"+ ]},"AWS::Lambda::Function/FileSystemConfig": {"type": "structure",@@ -454,7 +1055,11 @@"S3FilesConfig": "AWS::Lambda::Function/S3FilesConfig","Arn": "String","LocalMountPath": "String"- }+ },+ "required": [+ "Arn",+ "LocalMountPath"+ ]},"AWS::Lambda::Function/FunctionScalingConfig": {"type": "structure",@@ -485,7 +1090,10 @@"ExecutionEnvironmentMemoryGiBPerVCpu": "Double","CapacityProviderArn": "String","PerExecutionEnvironmentMaxConcurrency": "Integer"- }+ },+ "required": [+ "CapacityProviderArn"+ ]},"AWS::Lambda::Function/LoggingConfig": {"type": "structure",@@ -504,7 +1112,10 @@"members": {"UpdateRuntimeOn": "String","RuntimeVersionArn": "String"- }+ },+ "required": [+ "UpdateRuntimeOn"+ ]},"AWS::Lambda::Function/S3FilesConfig": {"type": "structure",@@ -516,7 +1127,10 @@"type": "structure","members": {"ApplyOn": "String"- }+ },+ "required": [+ "ApplyOn"+ ]},"AWS::Lambda::Function/SnapStartResponse": {"type": "structure",@@ -530,13 +1144,19 @@"members": {"Value": "String","Key": "String"- }+ },+ "required": [+ "Key"+ ]},"AWS::Lambda::Function/TenancyConfig": {"type": "structure","members": {"TenantIsolationMode": "String"- }+ },+ "required": [+ "TenantIsolationMode"+ ]},"AWS::Lambda::Function/TracingConfig": {"type": "structure",@@ -570,7 +1190,10 @@"Content": "AWS::Lambda::LayerVersion/Content","LayerVersionArn": "String","CompatibleArchitectures": "AWS::Lambda::LayerVersion.CompatibleArchitectures"- }+ },+ "required": [+ "Content"+ ]},"AWS::Lambda::LayerVersion.CompatibleArchitectures": {"type": "list",@@ -587,7 +1210,11 @@"S3Bucket": "String","S3Key": "String","S3ObjectStorageMode": "String"- }+ },+ "required": [+ "S3Bucket",+ "S3Key"+ ]},"Boolean": {"type": "boolean"diff --git a/src/test/java/io/github/hectorvent/floci/core/common/RequestShapeModelTest.java b/src/test/java/io/github/hectorvent/floci/core/common/RequestShapeModelTest.javaindex ffa70603aa..6230a06ebb 100644--- a/src/test/java/io/github/hectorvent/floci/core/common/RequestShapeModelTest.java+++ b/src/test/java/io/github/hectorvent/floci/core/common/RequestShapeModelTest.java@@ -23,7 +23,8 @@ class RequestShapeModelTest {"_source": {"generator": "test"},"operations": {"Send": "SendRequest"},"shapes": {- "SendRequest": {"type": "structure", "members": {"To": "Addresses", "Tags": "TagMap", "From": "Address"}},+ "SendRequest": {"type": "structure", "members": {"To": "Addresses", "Tags": "TagMap", "From": "Address"},+ "required": ["To", "From"]},"Addresses": {"type": "list", "member": "Address"},"TagMap": {"type": "map", "value": "Address"},"Address": {"type": "string"}@@ -35,7 +36,9 @@ class RequestShapeModelTest {Shape request = model.shapes().get("SendRequest");assertEquals("structure", request.type());assertEquals(List.of("To", "Tags", "From"), List.copyOf(request.members().keySet()));+ assertEquals(List.of("To", "From"), request.required());assertEquals("Address", model.shapes().get("Addresses").element());+ assertTrue(model.shapes().get("Addresses").required().isEmpty());assertEquals("Address", model.shapes().get("TagMap").element());Shape scalar = model.shapes().get("Address");assertEquals("string", scalar.type());@@ -59,6 +62,7 @@ class RequestShapeModelTest {assertThrows(UnsupportedOperationException.class, () -> model.shapes().remove("Address"));assertThrows(UnsupportedOperationException.class,() -> model.shapes().get("SendRequest").members().put("Cc", "Addresses"));+ assertThrows(UnsupportedOperationException.class, () -> model.shapes().get("SendRequest").required().add("To"));}@Testdiff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsTaskDefinitionModelIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsTaskDefinitionModelIntegrationTest.javanew file mode 100644index 0000000000..c21ed1b125--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsTaskDefinitionModelIntegrationTest.java@@ -0,0 +1,149 @@+package io.github.hectorvent.floci.services.cloudformation;++import io.github.hectorvent.floci.testing.PartitionCleanup;+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;+import io.quarkus.test.junit.QuarkusTest;+import io.restassured.specification.RequestSpecification;+import org.junit.jupiter.api.BeforeAll;+import org.junit.jupiter.api.Test;+import org.junit.jupiter.api.extension.RegisterExtension;++import java.util.List;++import static io.restassured.RestAssured.given;+import static org.hamcrest.MatcherAssert.assertThat;+import static org.hamcrest.Matchers.equalTo;+import static org.hamcrest.Matchers.hasItem;+import static org.junit.jupiter.api.Assertions.assertEquals;++/**+ * An {@code AWS::ECS::TaskDefinition} read as the ECS handler reads it. Measured on AWS (eu-west-1,+ * 2026-10-19): CloudFormation hands the properties over without template validation, every scalar+ * as text, and the handler converts them to its model's types. A value it cannot convert fails the+ * resource with every violation of the unconverted model, the Memory it could convert included;+ * a model that converts but lacks a required member fails with that member alone.+ */+@QuarkusTest+class CloudFormationEcsTaskDefinitionModelIntegrationTest {++ private static final String CFN_AUTH =+ "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/cloudformation/aws4_request";+ private static final String ECS_TARGET = "AmazonEC2ContainerServiceV20141113";+ private static final String MEMORY = "#/ContainerDefinitions/0/Memory: expected type: Integer, found: String."+ + " This may occur when a numeric value exceeds 32-bit integer max (2147483647). Consider using 'number'"+ + " type or ensure value fits in integer range.";+ /** A String and a CommaDelimitedList parameter of Linux capabilities. */+ private static final String PARAMETERS = """+ "Parameters": {+ "Str": {"Type": "String", "Default": "SYS_PTRACE"},+ "Csv": {"Type": "CommaDelimitedList", "Default": "SYS_PTRACE,NET_ADMIN"}+ },+ """;++ @RegisterExtension+ final PartitionCleanup cleanup = new PartitionCleanup();++ @BeforeAll+ static void configureRestAssured() {+ RestAssuredJsonUtils.configureAwsContentTypes();+ }++ @Test+ void aValueTheHandlerCannotConvertFailsTheCreateWithEveryViolation() {+ String memory = stackName("memory");+ submit("CreateStack", memory, template("", memory, "\"Name\": \"app\", \"Image\": \"busybox\", \"Memory\": \"abc\""));+ assertEquals("ROLLBACK_COMPLETE", CfnStackWaits.awaitTerminal(memory, CFN_AUTH).status());+ assertEventReason(memory, "Model validation failed (" + MEMORY + ")");++ String add = stackName("add");+ submit("CreateStack", add, template(PARAMETERS, add, "\"Name\": \"app\", \"Image\": \"busybox\", \"Memory\": 128,"+ + " \"LinuxParameters\": {\"Capabilities\": {\"Add\": {\"Ref\": \"Str\"}}}"));+ assertEquals("ROLLBACK_COMPLETE", CfnStackWaits.awaitTerminal(add, CFN_AUTH).status());+ assertEventReason(add, "Model validation failed (" + MEMORY + "\n#/ContainerDefinitions/0/LinuxParameters"+ + "/Capabilities/Add: expected type: JSONArray, found: String)");+ }++ @Test+ void aMissingRequiredMemberFailsTheCreateAlone() {+ String image = stackName("image");+ submit("CreateStack", image, template("", image, "\"Name\": \"app\", \"Memory\": 128"));+ assertEquals("ROLLBACK_COMPLETE", CfnStackWaits.awaitTerminal(image, CFN_AUTH).status());+ assertEventReason(image, "Model validation failed (#/ContainerDefinitions/0: required key [Image] not found)");+ }++ @Test+ void valuesTheHandlerConvertsAreRegisteredConverted() {+ String converted = stackName("converted");+ submit("CreateStack", converted, template(PARAMETERS, converted, "\"Name\": \"app\", \"Image\": \"busybox\","+ + " \"Memory\": \"+128\", \"LinuxParameters\": {\"Capabilities\": {\"Add\": {\"Ref\": \"Csv\"}}}},"+ + " {\"Name\": \"side\", \"Image\": \"busybox\", \"Memory\": 64, \"Essential\": \"False\""));+ assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(converted, CFN_AUTH).status());++ RestAssuredJsonUtils.awsAction(ECS_TARGET, "DescribeTaskDefinition", "{\"taskDefinition\": \"" + converted + "\"}")+ .then()+ .statusCode(200)+ .body("taskDefinition.containerDefinitions.find { it.name == 'app' }.memory", equalTo(128))+ .body("taskDefinition.containerDefinitions.find { it.name == 'side' }.essential", equalTo(false));+ }++ private String stackName(String purpose) {+ String name = "cfn-ecs-model-" + purpose + "-" + Long.toString(System.nanoTime(), 36);+ cleanup.register(() -> {+ submit("DeleteStack", name, null);+ CfnStackWaits.awaitStackDeleted(name, CFN_AUTH);+ });+ return name;+ }++ /**+ * A task definition of {@code family} whose containers are {@code containers}, the members of+ * each without its braces, after the template sections {@code sections}.+ */+ private static String template(String sections, String family, String containers) {+ return """+ {+ %s+ "Resources": {+ "TaskDef": {+ "Type": "AWS::ECS::TaskDefinition",+ "Properties": {+ "Family": "%s",+ "ContainerDefinitions": [{%s}]+ }+ }+ }+ }+ """.formatted(sections, family, containers);+ }++ private static void submit(String action, String stackName, String template) {+ RequestSpecification request = given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", CFN_AUTH)+ .formParam("Action", action)+ .formParam("StackName", stackName);+ if (template != null) {+ request.formParam("TemplateBody", template);+ }+ request+ .when()+ .post("/")+ .then()+ .statusCode(200);+ }++ /** The stack has an event whose reason is {@code reason}, read from the XML so its escapes are undone. */+ private static void assertEventReason(String stackName, String reason) {+ List<String> reasons = given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", CFN_AUTH)+ .formParam("Action", "DescribeStackEvents")+ .formParam("StackName", stackName)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .extract().xmlPath().getList("**.findAll { it.name() == 'ResourceStatusReason' }", String.class);+ assertThat(reasons, hasItem(reason));+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnPropertyTypesTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnPropertyTypesTest.javaindex c677312a0d..7015f21cef 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnPropertyTypesTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnPropertyTypesTest.java@@ -7,6 +7,11 @@ import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.common.RequestShapeModel;import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;import org.junit.jupiter.api.Test;+import org.junit.jupiter.params.ParameterizedTest;+import org.junit.jupiter.params.provider.Arguments;+import org.junit.jupiter.params.provider.MethodSource;++import java.util.stream.Stream;import static org.junit.jupiter.api.Assertions.assertEquals;import static org.junit.jupiter.api.Assertions.assertNull;@@ -14,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;import static org.junit.jupiter.api.Assertions.assertTrue;/**- * The property types vendored from the resource schemas, and the reader's walk over the shapes the+ * The property types vendored from the resource schemas, and the readers' walk over the shapes the* generator writes: structures, lists, maps, scalars and values the schema leaves free.*/class CfnPropertyTypesTest {@@ -50,6 +55,8 @@ class CfnPropertyTypesTest {CfnPropertyTypes.propertyShape("AWS::Lambda::LayerVersion", "CompatibleRuntimes"));assertEquals("AWS::AutoScaling::LaunchConfiguration/MetadataOptions",CfnPropertyTypes.propertyShape("AWS::AutoScaling::LaunchConfiguration", "MetadataOptions"));+ assertEquals("AWS::ECS::TaskDefinition.ContainerDefinitions",+ CfnPropertyTypes.propertyShape("AWS::ECS::TaskDefinition", "ContainerDefinitions"));}@Test@@ -91,6 +98,166 @@ class CfnPropertyTypesTest {.read("Config", json("{\"Ref\": \"AWS::NoValue\"}"), "AWS::Test::Thing/Config"));}+ private static final String 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.";+ private static final String CONTAINER = "#/ContainerDefinitions/0";+ private static final String MEMORY = CONTAINER + "/Memory: expected type: Integer, found: String" + HINT;+ private static final String LINUX = CONTAINER + "/LinuxParameters";++ /**+ * Measured on CloudFormation (eu-west-1, 2026-10-19): an AWS::ECS::TaskDefinition gets no+ * template validation, and the ECS handler fails it with every violation of the unconverted+ * model when a value does not convert, Memory 128 included, in the schema's order whatever the+ * template's; when every value converts, with the required members the model lacks, grouped+ * where their paths meet.+ */+ @ParameterizedTest(name = "{0}")+ @MethodSource("ecsTaskDefinitions")+ void anEcsTaskDefinitionFailsWhereTheEcsHandlerDoes(String measured, String properties, String violations) {+ AwsException e = assertThrows(AwsException.class, () -> new CfnPropertyTypes.HandlerReader(engine())+ .read("AWS::ECS::TaskDefinition", json(properties)));++ assertEquals("InvalidRequest", e.getErrorCode());+ assertEquals("Model validation failed (" + violations, e.getMessage());+ }++ static Stream<Arguments> ecsTaskDefinitions() {+ return Stream.of(+ Arguments.of("Add a string", container("\"Memory\": 128, \"LinuxParameters\": {\"Capabilities\": {\"Add\": \"SYS_PTRACE\"}}"),+ MEMORY + "\n" + LINUX + "/Capabilities/Add: expected type: JSONArray, found: String)"),+ Arguments.of("Add an object item", container("\"Memory\": 128, \"LinuxParameters\": {\"Capabilities\": {\"Add\": [{}]}}"),+ MEMORY + "\n" + LINUX + "/Capabilities/Add/0: expected type: String, found: JSONObject)"),+ Arguments.of("Capabilities a string", container("\"Memory\": 128, \"LinuxParameters\": {\"Capabilities\": \"x\"}"),+ MEMORY + "\n" + LINUX + "/Capabilities: expected type: JSONObject, found: String)"),+ Arguments.of("LinuxParameters a string", container("\"Memory\": 128, \"LinuxParameters\": \"x\""),+ MEMORY + "\n" + LINUX + ": expected type: JSONObject, found: String)"),+ Arguments.of("LinuxParameters a list", container("\"Memory\": 128, \"LinuxParameters\": [\"x\"]"),+ MEMORY + "\n" + LINUX + ": expected type: JSONObject, found: JSONArray)"),+ Arguments.of("InitProcessEnabled yes", container("\"Memory\": 128, \"LinuxParameters\": {\"InitProcessEnabled\": \"yes\"}"),+ MEMORY + "\n" + LINUX + "/InitProcessEnabled: expected type: Boolean, found: String)"),+ Arguments.of("InitProcessEnabled an object", container("\"Memory\": 128, \"LinuxParameters\": {\"InitProcessEnabled\": {}}"),+ MEMORY + "\n" + LINUX + "/InitProcessEnabled: expected type: Boolean, found: JSONObject)"),+ Arguments.of("SharedMemorySize abc", container("\"Memory\": 128, \"LinuxParameters\": {\"SharedMemorySize\": \"abc\"}"),+ MEMORY + "\n" + LINUX + "/SharedMemorySize: expected type: Integer, found: String" + HINT + ")"),+ Arguments.of("SharedMemorySize 4.5", container("\"Memory\": 128, \"LinuxParameters\": {\"SharedMemorySize\": 4.5}"),+ MEMORY + "\n" + LINUX + "/SharedMemorySize: expected type: Integer, found: String" + HINT + ")"),+ Arguments.of("SharedMemorySize true", container("\"Memory\": 128, \"LinuxParameters\": {\"SharedMemorySize\": true}"),+ MEMORY + "\n" + LINUX + "/SharedMemorySize: expected type: Integer, found: String" + HINT + ")"),+ Arguments.of("MaxSwap beyond 32 bits", container("\"Memory\": 128, \"LinuxParameters\": {\"MaxSwap\": 3000000000}"),+ MEMORY + "\n" + LINUX + "/MaxSwap: expected type: Integer, found: String" + HINT + ")"),+ Arguments.of("Devices a string", container("\"Memory\": 128, \"LinuxParameters\": {\"Devices\": \"x\"}"),+ MEMORY + "\n" + LINUX + "/Devices: expected type: JSONArray, found: String)"),+ Arguments.of("HostPath an object", container("\"Memory\": 128, \"LinuxParameters\": {\"Devices\": [{\"HostPath\": {}}]}"),+ MEMORY + "\n" + LINUX + "/Devices/0/HostPath: expected type: String, found: JSONObject)"),+ Arguments.of("MountOptions a string", container("\"Memory\": 128, \"LinuxParameters\": {\"Tmpfs\": [{\"ContainerPath\": \"/t\", \"Size\": 64, \"MountOptions\": \"rw\"}]}"),+ MEMORY + "\n" + LINUX + "/Tmpfs/0/Size: expected type: Integer, found: String" + HINT + "\n" + LINUX+ + "/Tmpfs/0/MountOptions: expected type: JSONArray, found: String)"),+ Arguments.of("MountOptions before Size in the template", container("\"Memory\": 128, \"LinuxParameters\": {\"Tmpfs\": [{\"MountOptions\": \"rw\", \"ContainerPath\": \"/t\", \"Size\": 64}]}"),+ MEMORY + "\n" + LINUX + "/Tmpfs/0/Size: expected type: Integer, found: String" + HINT + "\n" + LINUX+ + "/Tmpfs/0/MountOptions: expected type: JSONArray, found: String)"),+ Arguments.of("LinuxParameters before Memory in the template", "{\"ContainerDefinitions\": [{\"LinuxParameters\": {\"Capabilities\": {\"Add\": \"X\"}}, \"Memory\": 128, \"Name\": \"app\", \"Image\": \"busybox\"}]}",+ MEMORY + "\n" + LINUX + "/Capabilities/Add: expected type: JSONArray, found: String)"),+ Arguments.of("Memory abc", container("\"Memory\": \"abc\", \"LinuxParameters\": {}"), MEMORY + ")"),+ Arguments.of("Memory an object", container("\"Memory\": {}"),+ CONTAINER + "/Memory: expected type: Integer, found: JSONObject)"),+ Arguments.of("Essential tRuE", container("\"Memory\": 128, \"Essential\": \"tRuE\""),+ MEMORY + "\n" + CONTAINER + "/Essential: expected type: Boolean, found: String)"),+ Arguments.of("Essential 1", container("\"Memory\": 128, \"Essential\": \"1\""),+ MEMORY + "\n" + CONTAINER + "/Essential: expected type: Boolean, found: String)"),+ Arguments.of("Name an object", "{\"ContainerDefinitions\": [{\"Name\": {\"a\": 1}, \"Image\": \"busybox\", \"Memory\": 128}]}",+ MEMORY + "\n" + CONTAINER + "/Name: expected type: String, found: JSONObject)"),+ Arguments.of("ContainerDefinitions a string", "{\"ContainerDefinitions\": \"x\"}",+ "#/ContainerDefinitions: expected type: JSONArray, found: String)"),+ Arguments.of("a number for text", container("\"Memory\": 128, \"Environment\": [{\"Name\": \"A\", \"Value\": 5}], \"LinuxParameters\": {\"Devices\": \"x\"}"),+ MEMORY + "\n" + LINUX + "/Devices: expected type: JSONArray, found: String)"),+ Arguments.of("every integer and boolean, in the schema's order", container("\"Memory\": 128, \"PortMappings\": [{\"ContainerPort\": 80}], \"Essential\": true, \"LinuxParameters\": {\"Devices\": \"x\"}"),+ MEMORY + "\n" + CONTAINER + "/Essential: expected type: Boolean, found: String\n" + LINUX+ + "/Devices: expected type: JSONArray, found: String\n" + CONTAINER+ + "/PortMappings/0/ContainerPort: expected type: Integer, found: String" + HINT + ")"),+ Arguments.of("two containers", "{\"ContainerDefinitions\": [{\"Name\": \"a\", \"Image\": \"busybox\", \"Memory\": 128, \"Essential\": true},"+ + " {\"Name\": \"b\", \"Image\": \"busybox\", \"Memory\": 64, \"Essential\": false, \"LinuxParameters\": {\"Capabilities\": {\"Add\": \"X\"}}}]}",+ MEMORY + "\n" + CONTAINER + "/Essential: expected type: Boolean, found: String\n#/ContainerDefinitions/1/Memory:"+ + " expected type: Integer, found: String" + HINT + "\n#/ContainerDefinitions/1/Essential: expected type:"+ + " Boolean, found: String\n#/ContainerDefinitions/1/LinuxParameters/Capabilities/Add: expected type:"+ + " JSONArray, found: String)"),+ Arguments.of("the task level", "{\"Memory\": \"512\", \"EphemeralStorage\": {\"SizeInGiB\": 30}, \"ContainerDefinitions\": [{\"Name\": \"app\","+ + " \"Image\": \"busybox\", \"Cpu\": 10, \"LinuxParameters\": {\"Capabilities\": {\"Add\": \"X\"}, \"InitProcessEnabled\": true}}]}",+ CONTAINER + "/Cpu: expected type: Integer, found: String" + HINT + "\n" + LINUX+ + "/Capabilities/Add: expected type: JSONArray, found: String\n" + LINUX+ + "/InitProcessEnabled: expected type: Boolean, found: String\n#/EphemeralStorage/SizeInGiB: expected"+ + " type: Integer, found: String" + HINT + ")"),+ Arguments.of("a missing required member beside a type", container("\"Memory\": 128, \"LinuxParameters\": {\"Capabilities\": {\"Add\": \"X\"}, \"Tmpfs\": [{\"ContainerPath\": \"/t\"}]}"),+ MEMORY + "\n" + LINUX + "/Capabilities/Add: expected type: JSONArray, found: String\n" + LINUX+ + "/Tmpfs/0: required key [Size] not found)"),+ Arguments.of("required members before the object's members", container("\"Memory\": 128, \"LinuxParameters\": {\"Tmpfs\": [{\"ContainerPath\": \"/t\", \"MountOptions\": \"rw\"}]}"),+ MEMORY + "\n" + LINUX + "/Tmpfs/0: required key [Size] not found\n" + LINUX+ + "/Tmpfs/0/MountOptions: expected type: JSONArray, found: String)"),+ Arguments.of("no Name and no Image beside a type", "{\"ContainerDefinitions\": [{\"Memory\": 128, \"LinuxParameters\": {\"Capabilities\": {\"Add\": \"X\"}}}]}",+ CONTAINER + ": required key [Name] not found\n" + CONTAINER + ": required key [Image] not found\n" + MEMORY+ + "\n" + LINUX + "/Capabilities/Add: expected type: JSONArray, found: String)"),+ Arguments.of("Tmpfs without Size", container("\"Memory\": 128, \"LinuxParameters\": {\"Tmpfs\": [{\"ContainerPath\": \"/t\"}]}"),+ LINUX + "/Tmpfs/0: required key [Size] not found)"),+ Arguments.of("no Name", "{\"ContainerDefinitions\": [{\"Image\": \"busybox\", \"Memory\": 128}]}",+ CONTAINER + ": required key [Name] not found)"),+ Arguments.of("no Name and no Image", "{\"ContainerDefinitions\": [{\"Memory\": 128, \"Essential\": true}]}",+ CONTAINER + ": 2 schema violations found)\n" + CONTAINER + ": required key [Name] not found (" + CONTAINER+ + ")\n" + CONTAINER + ": required key [Image] not found (" + CONTAINER + ")"),+ Arguments.of("no Name and Tmpfs without Size", "{\"ContainerDefinitions\": [{\"Image\": \"busybox\", \"Memory\": 128,"+ + " \"LinuxParameters\": {\"Tmpfs\": [{\"ContainerPath\": \"/t\"}]}}]}",+ CONTAINER + ": 2 schema violations found)\n" + CONTAINER + ": required key [Name] not found (" + CONTAINER+ + ")\n" + LINUX + "/Tmpfs/0: required key [Size] not found (" + LINUX + "/Tmpfs/0)"),+ Arguments.of("an empty ulimit", container("\"Memory\": 128, \"Ulimits\": [{}]"),+ CONTAINER + "/Ulimits/0: 3 schema violations found)\n" + CONTAINER + "/Ulimits/0: required key [HardLimit] not"+ + " found (" + CONTAINER + "/Ulimits/0)\n" + CONTAINER + "/Ulimits/0: required key [Name] not found ("+ + CONTAINER + "/Ulimits/0)\n" + CONTAINER + "/Ulimits/0: required key [SoftLimit] not found ("+ + CONTAINER + "/Ulimits/0)"),+ Arguments.of("no Name and an empty ulimit", "{\"ContainerDefinitions\": [{\"Image\": \"busybox\", \"Memory\": 128, \"Ulimits\": [{}]}]}",+ CONTAINER + ": 4 schema violations found)\n" + CONTAINER + ": required key [Name] not found (" + CONTAINER+ + ")\n" + CONTAINER + "/Ulimits/0: 3 schema violations found (" + CONTAINER + "/Ulimits/0)"),+ Arguments.of("two containers without Name", "{\"ContainerDefinitions\": [{\"Image\": \"busybox\", \"Memory\": 128},"+ + " {\"Image\": \"busybox\", \"Memory\": 64}]}",+ "#/ContainerDefinitions: 2 schema violations found)\n" + CONTAINER + ": required key [Name] not found ("+ + CONTAINER + ")\n#/ContainerDefinitions/1: required key [Name] not found (#/ContainerDefinitions/1)"),+ Arguments.of("the task level and a container", "{\"ContainerDefinitions\": [{\"Image\": \"busybox\", \"Memory\": 128}],"+ + " \"ProxyConfiguration\": {\"Type\": \"APPMESH\"}}",+ "#: 2 schema violations found)\n#/ProxyConfiguration: required key [ContainerName] not found"+ + " (#/ProxyConfiguration)\n" + CONTAINER + ": required key [Name] not found (" + CONTAINER + ")"));+ }++ /** Measured: the values the ECS handler converts, and a number where text is expected, read as text. */+ @Test+ void anEcsTaskDefinitionIsConvertedAsTheEcsHandlerConvertsIt() {+ JsonNode read = new CfnPropertyTypes.HandlerReader(engine()).read("AWS::ECS::TaskDefinition", json("""+ {"Family": "web", "Memory": 512, "ContainerDefinitions": [+ {"Name": "a", "Image": "busybox", "Memory": "+128", "Essential": "True",+ "Environment": [{"Name": "A", "Value": 5}],+ "LinuxParameters": {"InitProcessEnabled": "TRUE", "SharedMemorySize": "64",+ "Devices": [{"HostPath": 5, "ContainerPath": "/dev/x"}]}},+ {"Name": "b", "Image": "busybox", "Memory": " 128", "Essential": " true"},+ {"Name": "c", "Image": "busybox", "Memory": "0128", "Cpu": {"Ref": "AWS::NoValue"}}]}+ """));++ assertEquals(json("""+ {"Family": "web", "Memory": "512", "ContainerDefinitions": [+ {"Name": "a", "Image": "busybox", "Memory": 128, "Essential": true,+ "Environment": [{"Name": "A", "Value": "5"}],+ "LinuxParameters": {"InitProcessEnabled": true, "SharedMemorySize": 64,+ "Devices": [{"HostPath": "5", "ContainerPath": "/dev/x"}]}},+ {"Name": "b", "Image": "busybox", "Memory": 128, "Essential": true},+ {"Name": "c", "Image": "busybox", "Memory": 128}]}+ """), read);+ }++ @Test+ void aResourceTypeTheVendoredFileLacksIsAnErrorOfTheBuild() {+ assertThrows(IllegalStateException.class,+ () -> new CfnPropertyTypes.HandlerReader(engine()).read("AWS::No::Type", json("{}")));+ }++ private static String container(String members) {+ return "{\"ContainerDefinitions\": [{\"Name\": \"app\", \"Image\": \"busybox\", " + members + "}]}";+ }+private static JsonNode read(String value, String shape) {CfnPropertyTypes.Reader reader = new CfnPropertyTypes.Reader(engine(), MODEL);JsonNode read = reader.read("Config", json(value), shape);diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EcsCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EcsCfnProvisionerTest.javaindex d181a8bb29..0625723f29 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EcsCfnProvisionerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EcsCfnProvisionerTest.java@@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test;import org.mockito.ArgumentCaptor;import org.mockito.InOrder;+import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Set;@@ -42,6 +43,7 @@ import static org.mockito.Mockito.mock;import static org.mockito.Mockito.never;import static org.mockito.Mockito.times;import static org.mockito.Mockito.verify;+import static org.mockito.Mockito.verifyNoMoreInteractions;import static org.mockito.Mockito.when;/**@@ -71,9 +73,15 @@ class EcsCfnProvisionerTest {return node == null || node.isMissingNode() || node.isNull() ? null : node.asText();});when(engine.resolveNode(any())).thenAnswer(inv -> inv.getArgument(0));+ when(engine.omitNoValue(any())).thenAnswer(inv -> inv.getArgument(0));// resolveStringList delegates to the real engine method; for the literal arrays these// tests use it just walks the array and calls resolve(...) per element, stubbed above.when(engine.resolveStringList(any())).thenCallRealMethod();+ when(engine.resolveLiteralList(any())).thenAnswer(inv -> {+ List<String> values = new ArrayList<>();+ ((JsonNode) inv.getArgument(0)).forEach(value -> values.add(value.asText()));+ return values;+ });return new ProvisionContext(engine, REGION, "000000000000", "my-stack", priorPhysicalId);}@@ -184,6 +192,45 @@ class EcsCfnProvisionerTest {assertEquals("fluentbit", def.getFirelensConfiguration().type());}+ /**+ * Measured (eu-west-1, 2026-10-19): the ECS handler converts text to the integers and booleans+ * its model declares, and a value it cannot convert fails the resource with its model+ * validation message before anything is registered.+ */+ @Test+ void taskDefinitionValuesAreReadAsTheEcsHandlerConvertsThem() {+ TaskDefinition td = new TaskDefinition();+ td.setTaskDefinitionArn(TASK_DEF_ARN);+ when(ecs.registerTaskDefinition(eq("web"), anyList(), isNull(), isNull(), isNull(), isNull(), isNull(),+ anyList(), eq(REGION))).thenReturn(td);+ ObjectNode props = mapper.createObjectNode().put("Family", "web");+ props.putArray("ContainerDefinitions").addObject()+ .put("Name", "app").put("Image", "nginx:1").put("Cpu", " 64").put("Memory", "+128")+ .put("Essential", "False");++ provisioner.provision(resource("AWS::ECS::TaskDefinition", "TaskDef"), props, ctx());++ @SuppressWarnings("unchecked")+ ArgumentCaptor<List<ContainerDefinition>> defs = ArgumentCaptor.forClass(List.class);+ verify(ecs).registerTaskDefinition(eq("web"), defs.capture(), isNull(), isNull(), isNull(), isNull(),+ isNull(), anyList(), eq(REGION));+ ContainerDefinition def = defs.getValue().get(0);+ assertEquals(64, def.getCpu());+ assertEquals(128, def.getMemory());+ assertFalse(def.isEssential());++ ((ObjectNode) props.get("ContainerDefinitions").get(0)).put("Memory", "abc");+ AwsException e = assertThrows(AwsException.class,+ () -> provisioner.provision(resource("AWS::ECS::TaskDefinition", "TaskDef"), props, ctx()));+ assertEquals("Model validation failed (#/ContainerDefinitions/0/Memory: expected type: Integer, found: String."+ + " This may occur when a numeric value exceeds 32-bit integer max (2147483647). Consider using"+ + " 'number' type or ensure value fits in integer range.\n#/ContainerDefinitions/0/Cpu: expected"+ + " type: Integer, found: String. This may occur when a numeric value exceeds 32-bit integer max"+ + " (2147483647). Consider using 'number' type or ensure value fits in integer range.\n"+ + "#/ContainerDefinitions/0/Essential: expected type: Boolean, found: String)", e.getMessage());+ verifyNoMoreInteractions(ecs);+ }+@Testvoid taskDefinitionWithoutFamilyGeneratesOneAndIgnoresAnUnknownNetworkMode() {TaskDefinition td = new TaskDefinition();diff --git a/tools/aws/regen_cfn_property_types.py b/tools/aws/regen_cfn_property_types.pyindex 741ef47fa7..bc9522a827 100644--- a/tools/aws/regen_cfn_property_types.py+++ b/tools/aws/regen_cfn_property_types.py@@ -4,8 +4,9 @@CloudFormation checks every resource property against the type the resource schema declaresbefore it touches any resource. `CfnPropertyTypes` does the same for the resource types whoseprovisioners read their properties through it, and needs only the types: for each resource type-its properties, and for every type reachable from one, whether it is an object and its members,-a list and its items, a map and its values, or a scalar.+its properties, and for every type reachable from one, whether it is an object, its members and+the ones it requires, a list and its items, a map and its values, or a scalar. Members keep the+schema's order, which a resource handler's model validation reports violations in.The schemas are the ones AWS publishes for us-east-1, the same `describe-type` returns:@@ -15,8 +16,8 @@ cfn-lint ships copies of them, but widens some types (a Lambda environment variaany JSON type there, a string in the published schema), so they are not used.The output has the request shapes' layout, so `RequestShapeModel` reads it: `operations` names each-resource type's properties shape, and `shapes` holds a `structure` for an object with properties,-a `list`, a `map` for an object keyed by pattern, `string`, `integer`, `boolean` or `double`, and+resource type's properties shape, and `shapes` holds a `structure` for an object with properties+(with `required` when the schema requires some of them), a `list`, a `map` for an object keyed by pattern, `string`, `integer`, `boolean` or `double`, and`json` for anything else (a free-form object, a value of several types), which is not checked.The archive is live rather than a pinned dependency and keeps no older copy, so, as with@@ -49,8 +50,8 @@ ARCHIVE_URL = "https://schema.cloudformation.us-east-1.amazonaws.com/CloudformatFETCH_TIMEOUT_SECONDS = 60# The resource types whose provisioners read their properties through CfnPropertyTypes.-RESOURCE_TYPES = ["AWS::AutoScaling::LaunchConfiguration", "AWS::Events::Rule", "AWS::Lambda::Function",- "AWS::Lambda::LayerVersion"]+RESOURCE_TYPES = ["AWS::AutoScaling::LaunchConfiguration", "AWS::ECS::TaskDefinition", "AWS::Events::Rule",+ "AWS::Lambda::Function", "AWS::Lambda::LayerVersion"]# The shared shape each scalar body is written as, inline; a definition keeps its own name.SCALAR_SHAPES = {"string": "String", "integer": "Integer", "boolean": "Boolean", "double": "Double", "json": "Json"}@@ -66,6 +67,15 @@ ANCHORS = {("AWS::Lambda::Function/Environment", "Variables"): {"String"},("AWS::Lambda::Function/EphemeralStorage", "Size"): "Integer",("AWS::AutoScaling::LaunchConfiguration/MetadataOptions", "HttpPutResponseHopLimit"): "Integer",+ ("AWS::ECS::TaskDefinition/ContainerDefinition", "Memory"): "Integer",+ ("AWS::ECS::TaskDefinition/ContainerDefinition", "Essential"): "Boolean",+ ("AWS::ECS::TaskDefinition/KernelCapabilities", "Add"): ["String"],+}++# Required members the provisioners rely on, measured the same way: shape -> its required members.+REQUIRED_ANCHORS = {+ "AWS::ECS::TaskDefinition/ContainerDefinition": ["Name", "Image"],+ "AWS::ECS::TaskDefinition/Tmpfs": ["Size"],}@@ -95,7 +105,7 @@ def build(schemas: dict[str, dict], provenance: str) -> dict:operations = {}for resource_type in RESOURCE_TYPES:schema = schemas[resource_type]- properties = {"type": "object", "properties": schema["properties"]}+ properties = {"type": "object", "properties": schema["properties"], "required": schema.get("required", [])}operations[resource_type] = shape_for(schema, resource_type, resource_type, properties, shapes)return {"_source": {@@ -137,9 +147,12 @@ def body_of(schema: dict, resource_type: str, name: str, node: dict, shapes: dickind = "object"if kind == "object":if "properties" in node:- return {"type": "structure", "members": {+ structure = {"type": "structure", "members": {member: shape_for(schema, resource_type, f"{name}.{member}", spec, shapes)for member, spec in node["properties"].items()}}+ if node.get("required"):+ structure["required"] = list(node["required"])+ return structurevalues = list(node.get("patternProperties", {}).values())if isinstance(node.get("additionalProperties"), dict):values.append(node["additionalProperties"])@@ -174,6 +187,9 @@ def validate(document: dict) -> list[str]:for target in named:if target not in shapes:problems.append(f"{name} names the missing shape {target!r}")+ for member in shape.get("required", []):+ if member not in shape.get("members", {}):+ problems.append(f"{name} requires {member!r}, which it does not declare")for (shape, member), expected in ANCHORS.items():target = shapes.get(shape, {}).get("members", {}).get(member)actual = shapes.get(target, {}) if target else {}@@ -185,6 +201,10 @@ def validate(document: dict) -> list[str]:holds = target == expectedif not holds:problems.append(f"expected {shape}.{member} to be {expected}, not {target} {actual}")+ for shape, required in REQUIRED_ANCHORS.items():+ actual = shapes.get(shape, {}).get("required", [])+ if actual != required:+ problems.append(f"expected {shape} to require {required}, not {actual}")return problemsdiff --git a/tools/aws/test_regen_cfn_property_types.py b/tools/aws/test_regen_cfn_property_types.pyindex 6e75291160..29e444eb83 100644--- a/tools/aws/test_regen_cfn_property_types.py+++ b/tools/aws/test_regen_cfn_property_types.py@@ -11,7 +11,7 @@ import regen_cfn_property_types as rSCHEMA = {"typeName": "AWS::Test::Thing","definitions": {- "Target": {"type": "object", "properties": {+ "Target": {"type": "object", "required": ["Id"], "properties": {"Id": {"type": "string"},"Retry": {"$ref": "#/definitions/Retry"},"Labels": {"type": "array", "items": {"type": "string"}},@@ -28,6 +28,7 @@ SCHEMA = {"Pattern": {"type": "object"},"Tags": {"type": "array", "items": {"type": "object", "properties": {"Key": {"type": "string"}}}},},+ "required": ["Name"],}@@ -45,11 +46,13 @@ def test_each_schema_type_becomes_a_shape(monkeypatch):assert doc["operations"] == {"AWS::Test::Thing": "AWS::Test::Thing"}shapes = doc["shapes"]assert shapes["AWS::Test::Thing"] == {"type": "structure", "members": {- "Name": "String", "Targets": "AWS::Test::Thing.Targets", "Pattern": "Json", "Tags": "AWS::Test::Thing.Tags"}}+ "Name": "String", "Targets": "AWS::Test::Thing.Targets", "Pattern": "Json", "Tags": "AWS::Test::Thing.Tags"},+ "required": ["Name"]}assert shapes["AWS::Test::Thing.Targets"] == {"type": "list", "member": "AWS::Test::Thing/Target"}assert shapes["AWS::Test::Thing/Target"] == {"type": "structure", "members": {"Id": "String", "Retry": "AWS::Test::Thing/Retry", "Labels": "AWS::Test::Thing/Target.Labels",- "Headers": "AWS::Test::Thing/Target.Headers", "Body": "Json", "Children": "AWS::Test::Thing/Target.Children"}}+ "Headers": "AWS::Test::Thing/Target.Headers", "Body": "Json", "Children": "AWS::Test::Thing/Target.Children"},+ "required": ["Id"]}assert shapes["AWS::Test::Thing/Target.Labels"] == {"type": "list", "member": "String"}assert shapes["AWS::Test::Thing/Target.Headers"] == {"type": "map", "value": "String"}assert shapes["AWS::Test::Thing/Target.Children"] == {"type": "list", "member": "AWS::Test::Thing/Target"}@@ -69,11 +72,14 @@ def test_validate_names_a_missing_shape_and_a_broken_anchor():doc = json.loads(r.OUTPUT.read_text(encoding="utf-8"))doc["shapes"]["AWS::Events::Rule/RetryPolicy"]["members"]["MaximumRetryAttempts"] = "String"doc["shapes"]["AWS::Events::Rule/Target"]["members"]["Gone"] = "AWS::Events::Rule/Gone"+ doc["shapes"]["AWS::ECS::TaskDefinition/Tmpfs"]["required"] = ["Size", "Absent"]problems = r.validate(doc)assert any("missing shape 'AWS::Events::Rule/Gone'" in problem for problem in problems)assert any("AWS::Events::Rule/RetryPolicy.MaximumRetryAttempts" in problem for problem in problems)+ assert any("requires 'Absent', which it does not declare" in problem for problem in problems)+ assert any("AWS::ECS::TaskDefinition/Tmpfs to require ['Size']" in problem for problem in problems)def test_verify_reports_a_schema_aws_has_changed(tmp_path, monkeypatch):