diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CloudFormationEcsLinuxParametersTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CloudFormationEcsLinuxParametersTest.java new file mode 100644 index 0000000000..e8ccff833e --- /dev/null +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CloudFormationEcsLinuxParametersTest.java @@ -0,0 +1,99 @@ +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 software.amazon.awssdk.services.ecs.model.LinuxParameters; +import software.amazon.awssdk.services.ecs.model.Tmpfs; + +import java.time.Duration; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * A container's {@code LinuxParameters} in an {@code AWS::ECS::TaskDefinition} reach the task + * definition, as the ECS SDK reads it back, and a Fargate template asking for swap fails as + * {@code RegisterTaskDefinition} refuses it. + */ +@DisplayName("CloudFormation AWS::ECS::TaskDefinition LinuxParameters") +class CloudFormationEcsLinuxParametersTest { + + private static final Duration DEPLOY_TIMEOUT = + TestFixtures.isRealAws() ? Duration.ofMinutes(10) : Duration.ofSeconds(10); + private static final String LINUX_STACK = TestFixtures.uniqueName("compat-cfn-linux"); + private static final String FARGATE_STACK = TestFixtures.uniqueName("compat-cfn-linux-fargate"); + + private static CloudFormationClient cloudFormation; + private static EcsClient ecs; + + @BeforeAll + static void setup() { + cloudFormation = TestFixtures.cloudFormationClient(); + ecs = TestFixtures.ecsClient(); + } + + @AfterAll + static void cleanup() { + if (cloudFormation != null) { + // DeleteStack answers for a stack that is gone too, so a failure here is a real one. + cloudFormation.deleteStack(r -> r.stackName(LINUX_STACK)); + cloudFormation.deleteStack(r -> r.stackName(FARGATE_STACK)); + cloudFormation.close(); + } + if (ecs != null) { + ecs.close(); + } + } + + @Test + void linuxParametersReachTheTaskDefinition() throws InterruptedException { + String name = LINUX_STACK; + cloudFormation.createStack(r -> r.stackName(name).templateBody(""" + {"Resources": {"TaskDef": {"Type": "AWS::ECS::TaskDefinition", "Properties": { + "Family": "%s", "RequiresCompatibilities": ["EC2"], "NetworkMode": "bridge", + "ContainerDefinitions": [{"Name": "worker", "Image": "busybox", "Memory": 512, + "LinuxParameters": {"InitProcessEnabled": true, + "Capabilities": {"Add": ["SYS_PTRACE"], "Drop": ["NET_RAW"]}, + "SharedMemorySize": 256, "MaxSwap": 1024, "Swappiness": 10, + "Tmpfs": [{"ContainerPath": "/scratch", "Size": 64, "MountOptions": ["noexec"]}]}}]}}}} + """.formatted(name))); + assertThat(TestFixtures.awaitStackTerminal(cloudFormation, name, DEPLOY_TIMEOUT)).isEqualTo("CREATE_COMPLETE"); + + ContainerDefinition container = ecs.describeTaskDefinition(r -> r.taskDefinition(name)) + .taskDefinition().containerDefinitions().get(0); + LinuxParameters linux = container.linuxParameters(); + assertThat(linux.initProcessEnabled()).isTrue(); + assertThat(linux.capabilities().add()).containsExactly("SYS_PTRACE"); + assertThat(linux.capabilities().drop()).containsExactly("NET_RAW"); + assertThat(linux.sharedMemorySize()).isEqualTo(256); + assertThat(linux.maxSwap()).isEqualTo(1024); + assertThat(linux.swappiness()).isEqualTo(10); + Tmpfs tmpfs = linux.tmpfs().get(0); + assertThat(tmpfs.containerPath()).isEqualTo("/scratch"); + assertThat(tmpfs.size()).isEqualTo(64); + assertThat(tmpfs.mountOptions()).containsExactly("noexec"); + } + + @Test + void aFargateTemplateAskingForSwapFailsAsRegisterTaskDefinitionDoes() throws InterruptedException { + String name = FARGATE_STACK; + cloudFormation.createStack(r -> r.stackName(name).templateBody(""" + {"Resources": {"TaskDef": {"Type": "AWS::ECS::TaskDefinition", "Properties": { + "Family": "%s", "RequiresCompatibilities": ["FARGATE"], "NetworkMode": "awsvpc", + "Cpu": "256", "Memory": "512", + "ContainerDefinitions": [{"Name": "worker", "Image": "busybox", + "LinuxParameters": {"MaxSwap": 512, "Swappiness": 10}}]}}}} + """.formatted(name))); + assertThat(TestFixtures.awaitStackTerminal(cloudFormation, name, DEPLOY_TIMEOUT)).isEqualTo("ROLLBACK_COMPLETE"); + + List events = cloudFormation.describeStackEvents(r -> r.stackName(name)).stackEvents(); + assertThat(events).anySatisfy(event -> assertThat(event.resourceStatusReason()) + .contains("Fargate compatible task definitions do not support maxSwap")); + } +} 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.java index 2f8d79c7ac..3de102fe16 100644 --- 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.java @@ -25,7 +25,8 @@ import static org.assertj.core.api.Assertions.assertThat; @DisplayName("CloudFormation ECS task definition model") class CloudFormationEcsTaskDefinitionModelTest { - private static final Duration DEPLOY_TIMEOUT = Duration.ofSeconds(60); + private static final Duration DEPLOY_TIMEOUT = + TestFixtures.isRealAws() ? Duration.ofMinutes(10) : Duration.ofSeconds(10); 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" diff --git a/docs/services/ecs.md b/docs/services/ecs.md index 4e9fbc1c18..8fe58cce89 100644 --- a/docs/services/ecs.md +++ b/docs/services/ecs.md @@ -70,7 +70,12 @@ such as `proxyConfiguration`, `ulimits`, `resourceRequirements`, `systemControls` and placement constraints, is kept verbatim and returned as registered. A client that reads back what it wrote (Terraform, or a deploy tool verifying its own `RegisterTaskDefinition`) sees no drift. `runtimePlatform` does not change where a local task -runs: Floci launches every task on the host's own architecture. +runs: Floci launches every task on the host's own architecture. An `AWS::ECS::TaskDefinition` in a +CloudFormation template carries its containers' `LinuxParameters` into the same place, read as the +ECS handler reads them (see [CloudFormation](cloudformation.md#ecs-task-definitions)), so they are +returned in the API's shape and checked against the Fargate rules below exactly as if the task +definition had been registered through the API. As CloudFormation's handler does, it sends the +`devices` and `tmpfs` lists empty when the template has none. The round trip reaches inside the members Floci does parse. A port mapping keeps its `name`, `appProtocol` and `containerPortRange`, which is what a service's `serviceConnectConfiguration` 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.java index 603bf1ce28..693791182e 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 @@ -352,6 +352,12 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner { def.setSecrets(parseSecrets(item.path("Secrets"))); def.setLogConfiguration(parseLogConfiguration(item.path("LogConfiguration"))); def.setFirelensConfiguration(parseFirelensConfiguration(item.path("FirelensConfiguration"))); + Map linuxParameters = parseLinuxParameters(item.path("LinuxParameters")); + if (linuxParameters != null) { + Map unparsed = new LinkedHashMap<>(); + unparsed.put("linuxParameters", linuxParameters); + def.setUnparsed(unparsed); + } if (item.path("Command").isArray()) { def.setCommand(toStringList(item.path("Command"))); } @@ -372,6 +378,68 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner { node.has("SecretOptions") ? parseSecrets(node.path("SecretOptions")) : null); } + /** + * A container's {@code LinuxParameters}, read as the ECS handler reads them, in the shape + * RegisterTaskDefinition takes them, and kept where that path keeps them: among the + * definition's unparsed members, under {@code linuxParameters}. So DescribeTaskDefinition shows + * them and the Fargate rules on them apply, as for a definition registered through the API. + * The devices and tmpfs lists are always sent, empty when the template has none, as + * CloudFormation's handler sends them (measured). + */ + private static Map parseLinuxParameters(JsonNode node) { + if (!node.isObject()) { + return null; + } + Map result = new LinkedHashMap<>(); + JsonNode capabilities = node.path("Capabilities"); + if (capabilities.isObject()) { + Map kernelCapabilities = new LinkedHashMap<>(); + putStringList(kernelCapabilities, "add", capabilities.path("Add")); + putStringList(kernelCapabilities, "drop", capabilities.path("Drop")); + result.put("capabilities", kernelCapabilities); + } + List> devices = new ArrayList<>(); + for (JsonNode item : node.path("Devices")) { + Map device = new LinkedHashMap<>(); + putValue(device, "hostPath", item.path("HostPath")); + putValue(device, "containerPath", item.path("ContainerPath")); + putStringList(device, "permissions", item.path("Permissions")); + devices.add(device); + } + result.put("devices", devices); + putValue(result, "initProcessEnabled", node.path("InitProcessEnabled")); + putValue(result, "maxSwap", node.path("MaxSwap")); + putValue(result, "sharedMemorySize", node.path("SharedMemorySize")); + putValue(result, "swappiness", node.path("Swappiness")); + List> mounts = new ArrayList<>(); + for (JsonNode item : node.path("Tmpfs")) { + Map mount = new LinkedHashMap<>(); + putValue(mount, "containerPath", item.path("ContainerPath")); + putStringList(mount, "mountOptions", item.path("MountOptions")); + putValue(mount, "size", item.path("Size")); + mounts.add(mount); + } + result.put("tmpfs", mounts); + return result; + } + + /** A member the template sets, as the text, integer or boolean the handler converted it to. */ + private static void putValue(Map target, String key, JsonNode value) { + if (value.isTextual()) { + target.put(key, value.textValue()); + } else if (value.isInt()) { + target.put(key, value.intValue()); + } else if (value.isBoolean()) { + target.put(key, value.booleanValue()); + } + } + + private static void putStringList(Map target, String key, JsonNode value) { + if (value.isArray()) { + target.put(key, toStringList(value)); + } + } + private static FirelensConfiguration parseFirelensConfiguration(JsonNode node) { if (node == null || !node.isObject() || !node.hasNonNull("Type")) { return null; diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsLinuxParametersIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsLinuxParametersIntegrationTest.java new file mode 100644 index 0000000000..7fb7482119 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEcsLinuxParametersIntegrationTest.java @@ -0,0 +1,217 @@ +package io.github.hectorvent.floci.services.cloudformation; + +import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.QuarkusTestProfile; +import io.quarkus.test.junit.TestProfile; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * An {@code AWS::ECS::TaskDefinition} container's {@code LinuxParameters} reach the task + * definition as RegisterTaskDefinition keeps them: DescribeTaskDefinition shows them in the API's + * shape, and the Fargate rules RegisterTaskDefinition applies to them apply to a template too. + */ +@QuarkusTest +@TestProfile(CloudFormationEcsLinuxParametersIntegrationTest.DeviceProfile.class) +class CloudFormationEcsLinuxParametersIntegrationTest { + + /** + * Floci refuses a host path outside {@code floci.services.ecs.host-volume-roots} by default; the + * template's device, {@code /dev/fuse}, is let through. + */ + public static final class DeviceProfile implements QuarkusTestProfile { + @Override + public Map getConfigOverrides() { + return Map.of("floci.services.ecs.host-volume-roots", "/dev/fuse"); + } + } + + private static final String ECS_CT = "application/x-amz-json-1.1"; + private static final String ECS_TARGET = "AmazonEC2ContainerServiceV20141113."; + + /** + * The stacks a test asked for, each named afresh per run so a run never meets another run's. + * They are deleted after each test, and a delete CloudFormation does not accept fails there, + * reported apart from the test's own failure; deleting a stack that was never created answers + * 200 and is a no-op. + */ + private final List stacksToDelete = new ArrayList<>(); + + @AfterEach + void deleteStacks() { + for (String name : stacksToDelete) { + given().contentType("application/x-www-form-urlencoded") + .formParam("Action", "DeleteStack") + .formParam("StackName", name) + .when().post("/").then().statusCode(200); + CfnStackWaits.awaitStackDeleted(name); + } + stacksToDelete.clear(); + } + + @BeforeAll + static void configureRestAssured() { + RestAssuredJsonUtils.configureAwsContentTypes(); + } + + @Test + void linuxParametersReachTheTaskDefinition() { + String name = "cfn-linux-parameters-" + System.nanoTime(); + String template = """ + { + "Parameters": {"Shm": {"Type": "Number", "Default": "256"}}, + "Resources": { + "TaskDef": { + "Type": "AWS::ECS::TaskDefinition", + "Properties": { + "Family": "%s", + "RequiresCompatibilities": ["EC2"], + "NetworkMode": "bridge", + "ContainerDefinitions": [ + { + "Name": "worker", "Image": "busybox", "Memory": 512, + "LinuxParameters": { + "InitProcessEnabled": true, + "Capabilities": {"Add": ["SYS_PTRACE"], "Drop": ["NET_RAW"]}, + "Devices": [{"HostPath": "/dev/fuse", "ContainerPath": "/dev/fuse", + "Permissions": ["read", "write"]}], + "SharedMemorySize": {"Ref": "Shm"}, + "MaxSwap": 1024, + "Swappiness": 10, + "Tmpfs": [{"ContainerPath": "/scratch", "Size": 64, "MountOptions": ["noexec"]}] + } + }, + {"Name": "plain", "Image": "busybox", "Memory": 128, "Essential": false} + ] + } + } + } + } + """; + stacksToDelete.add(name); + createStack(name, template.formatted(name)); + assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(name).status()); + + given().contentType(ECS_CT) + .header("X-Amz-Target", ECS_TARGET + "DescribeTaskDefinition") + .body("{\"taskDefinition\":\"" + name + "\"}") + .when().post("/").then().statusCode(200) + .body("taskDefinition.containerDefinitions[0].name", equalTo("worker")) + .body("taskDefinition.containerDefinitions[0].linuxParameters", equalTo(Map.of( + "initProcessEnabled", true, + "capabilities", Map.of("add", List.of("SYS_PTRACE"), "drop", List.of("NET_RAW")), + "devices", List.of(Map.of("hostPath", "/dev/fuse", "containerPath", "/dev/fuse", + "permissions", List.of("read", "write"))), + "sharedMemorySize", 256, + "maxSwap", 1024, + "swappiness", 10, + "tmpfs", List.of(Map.of("containerPath", "/scratch", "size", 64, + "mountOptions", List.of("noexec")))))) + .body("taskDefinition.containerDefinitions[1].name", equalTo("plain")) + .body("taskDefinition.containerDefinitions[1]", not(hasKey("linuxParameters"))); + } + + @Test + void aFargateTemplateAskingForSwapFailsAsRegisterTaskDefinitionDoes() { + String name = "cfn-linux-parameters-fargate-" + System.nanoTime(); + String template = """ + { + "Resources": { + "TaskDef": { + "Type": "AWS::ECS::TaskDefinition", + "Properties": { + "Family": "%s", + "RequiresCompatibilities": ["FARGATE"], + "NetworkMode": "awsvpc", + "Cpu": "256", + "Memory": "512", + "ContainerDefinitions": [ + {"Name": "worker", "Image": "busybox", "LinuxParameters": {"MaxSwap": 512, "Swappiness": 10}} + ] + } + } + } + } + """; + stacksToDelete.add(name); + createStack(name, template.formatted(name)); + assertFargateSwapRefused(name, CfnStackWaits.awaitTerminal(name)); + } + + /** + * Measured (eu-west-1, 2026-10-16): AWS::NoValue in a list leaves its entry out, and the devices + * and tmpfs lists are registered empty when the template has none. + */ + @Test + void aNoValueInAListLeavesItsEntryOut() { + String name = "cfn-linux-parameters-novalue-" + System.nanoTime(); + String template = """ + { + "Conditions": {"Never": {"Fn::Equals": ["a", "b"]}}, + "Resources": { + "TaskDef": { + "Type": "AWS::ECS::TaskDefinition", + "Properties": { + "Family": "%s", + "RequiresCompatibilities": ["EC2"], + "ContainerDefinitions": [{ + "Name": "worker", "Image": "busybox", "Memory": 512, + "LinuxParameters": { + "Capabilities": { + "Add": [{"Fn::If": ["Never", "SYS_PTRACE", {"Ref": "AWS::NoValue"}]}], + "Drop": ["NET_RAW", {"Fn::If": ["Never", "MKNOD", {"Ref": "AWS::NoValue"}]}]}, + "Devices": [{"Fn::If": ["Never", {"HostPath": "/dev/null"}, {"Ref": "AWS::NoValue"}]}] + } + }] + } + } + } + } + """; + stacksToDelete.add(name); + createStack(name, template.formatted(name)); + assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(name).status()); + + given().contentType(ECS_CT) + .header("X-Amz-Target", ECS_TARGET + "DescribeTaskDefinition") + .body("{\"taskDefinition\":\"" + name + "\"}") + .when().post("/").then().statusCode(200) + .body("taskDefinition.containerDefinitions[0].linuxParameters", equalTo(Map.of( + "capabilities", Map.of("add", List.of(), "drop", List.of("NET_RAW")), + "devices", List.of(), + "tmpfs", List.of()))); + } + + private static void assertFargateSwapRefused(String name, CfnStackWaits.StackState state) { + assertEquals("ROLLBACK_COMPLETE", state.status()); + List reasons = given().contentType("application/x-www-form-urlencoded") + .formParam("Action", "DescribeStackEvents") + .formParam("StackName", name) + .when().post("/").then().statusCode(200).extract().xmlPath() + .getList("**.findAll { it.name() == 'ResourceStatusReason' }", String.class); + assertTrue(reasons.stream().anyMatch(reason -> reason != null + && reason.contains("Fargate compatible task definitions do not support maxSwap")), + reasons.toString()); + } + + private static void createStack(String name, String template) { + given().contentType("application/x-www-form-urlencoded") + .formParam("Action", "CreateStack") + .formParam("StackName", name) + .formParam("TemplateBody", template) + .when().post("/").then().statusCode(200); + } +} 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.java index 0625723f29..fd38ab9e98 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 @@ -23,6 +23,7 @@ import org.mockito.InOrder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -231,6 +232,84 @@ class EcsCfnProvisionerTest { verifyNoMoreInteractions(ecs); } + @Test + void containerLinuxParametersReachTheTaskDefinitionInTheApiShape() { + TaskDefinition td = new TaskDefinition(); + td.setTaskDefinitionArn(TASK_DEF_ARN); + when(ecs.registerTaskDefinition(anyString(), anyList(), any(), any(), any(), any(), any(), anyList(), + eq(REGION))).thenReturn(td); + + ObjectNode props = mapper.createObjectNode().put("Family", "web"); + ObjectNode container = props.putArray("ContainerDefinitions").addObject() + .put("Name", "app").put("Image", "nginx:1"); + ObjectNode linux = container.putObject("LinuxParameters") + .put("InitProcessEnabled", true).put("MaxSwap", 512).put("SharedMemorySize", 256) + .put("Swappiness", 10); + ObjectNode capabilities = linux.putObject("Capabilities"); + capabilities.putArray("Add").add("SYS_PTRACE"); + capabilities.putArray("Drop").add("NET_RAW").add("MKNOD"); + ObjectNode device = linux.putArray("Devices").addObject() + .put("HostPath", "/dev/fuse").put("ContainerPath", "/dev/fuse"); + device.putArray("Permissions").add("read").add("write"); + ObjectNode tmpfs = linux.putArray("Tmpfs").addObject().put("ContainerPath", "/scratch").put("Size", 64); + tmpfs.putArray("MountOptions").add("noexec").add("nosuid"); + + provisioner.provision(resource("AWS::ECS::TaskDefinition", "TaskDef"), props, ctx()); + + assertEquals(Map.of("linuxParameters", Map.of( + "capabilities", Map.of("add", List.of("SYS_PTRACE"), "drop", List.of("NET_RAW", "MKNOD")), + "devices", List.of(Map.of("hostPath", "/dev/fuse", "containerPath", "/dev/fuse", + "permissions", List.of("read", "write"))), + "initProcessEnabled", true, + "maxSwap", 512, + "sharedMemorySize", 256, + "swappiness", 10, + "tmpfs", List.of(Map.of("containerPath", "/scratch", "mountOptions", List.of("noexec", "nosuid"), + "size", 64)))), + registeredContainer().getUnparsed()); + } + + /** Text a parameter resolved to is converted as the ECS handler converts it (measured). */ + @Test + void linuxParametersGivenAsTextAreReadAsTheEcsHandlerConvertsThem() { + TaskDefinition td = new TaskDefinition(); + td.setTaskDefinitionArn(TASK_DEF_ARN); + when(ecs.registerTaskDefinition(anyString(), anyList(), any(), any(), any(), any(), any(), anyList(), + eq(REGION))).thenReturn(td); + + ObjectNode props = mapper.createObjectNode().put("Family", "web"); + props.putArray("ContainerDefinitions").addObject().put("Name", "app").put("Image", "nginx:1") + .putObject("LinuxParameters").put("InitProcessEnabled", "TRUE").put("SharedMemorySize", "64"); + + provisioner.provision(resource("AWS::ECS::TaskDefinition", "TaskDef"), props, ctx()); + + assertEquals(Map.of("linuxParameters", Map.of("initProcessEnabled", true, "sharedMemorySize", 64, + "devices", List.of(), "tmpfs", List.of())), + registeredContainer().getUnparsed()); + } + + @Test + void aContainerWithoutLinuxParametersCarriesNone() { + TaskDefinition td = new TaskDefinition(); + td.setTaskDefinitionArn(TASK_DEF_ARN); + when(ecs.registerTaskDefinition(anyString(), anyList(), any(), any(), any(), any(), any(), anyList(), + eq(REGION))).thenReturn(td); + + ObjectNode props = mapper.createObjectNode().put("Family", "web"); + props.putArray("ContainerDefinitions").addObject().put("Name", "app").put("Image", "nginx:1"); + provisioner.provision(resource("AWS::ECS::TaskDefinition", "TaskDef"), props, ctx()); + + assertNull(registeredContainer().getUnparsed()); + } + + private ContainerDefinition registeredContainer() { + @SuppressWarnings("unchecked") + ArgumentCaptor> defs = ArgumentCaptor.forClass(List.class); + verify(ecs).registerTaskDefinition(anyString(), defs.capture(), any(), any(), any(), any(), any(), + anyList(), eq(REGION)); + return defs.getValue().get(0); + } + @Test void taskDefinitionWithoutFamilyGeneratesOneAndIgnoresAnUnknownNetworkMode() { TaskDefinition td = new TaskDefinition();