Repository: ansible-collections/community.aws

Issue:
Unable to configure runtimePlatform in ECS Task Definition to use ARM
### Summary

I am trying to create task definitions via Ansible, however runtimePlatform can not be configured, this means it is always the default:
```
    "runtimePlatform": {
        "cpuArchitecture": "X86_64",
        "operatingSystemFamily": "LINUX"
    },
```

Runtime Platform should be configurable to make use of ARM instances on AWS Fargate. And I am pretty sure, this way also Windows systems on fargate could be supported, however no idea if fargate supports windows currently, windows is not my area :-D

Currently I am writing a patch to support this, the issue is just to link my PR :)

### Issue Type

Feature Idea

### Component Name

ecs_task_definition

### Additional Information

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)

```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:

Resolving patch:
diff --git a/plugins/modules/ecs_taskdefinition.py b/plugins/modules/ecs_taskdefinition.py
--- a/plugins/modules/ecs_taskdefinition.py
+++ b/plugins/modules/ecs_taskdefinition.py
@@ -627,6 +627,27 @@
             expression:
                 description: A cluster query language expression to apply to the constraint.
                 type: str
+    runtime_platform:
+        version_added: 6.4.0
+        description:
+            - runtime platform configuration for the task
+        required: false
+        type: dict
+        default: {
+                    "operatingSystemFamily": "LINUX",
+                    "cpuArchitecture": "X86_64"
+                }
+        suboptions:
+            cpuArchitecture:
+                description: The CPU Architecture type to be used by the task
+                type: str
+                required: false
+                choices: ['X86_64', 'ARM64']
+            operatingSystemFamily:
+                description: OS type to be used by the task
+                type: str
+                required: false
+                choices: ['LINUX', 'WINDOWS_SERVER_2019_FULL', 'WINDOWS_SERVER_2019_CORE', 'WINDOWS_SERVER_2022_FULL', 'WINDOWS_SERVER_2022_CORE']
 extends_documentation_fragment:
     - amazon.aws.common.modules
     - amazon.aws.region.modules
@@ -813,6 +834,7 @@ def register_task(
         cpu,
         memory,
         placement_constraints,
+        runtime_platform,
     ):
         validated_containers = []
 
@@ -873,6 +895,8 @@ def register_task(
             params["executionRoleArn"] = execution_role_arn
         if placement_constraints:
             params["placementConstraints"] = placement_constraints
+        if runtime_platform:
+            params["runtimePlatform"] = runtime_platform
 
         try:
             response = self.ecs.register_task_definition(aws_retry=True, **params)
@@ -939,6 +963,24 @@ def main():
             elements="dict",
             options=dict(type=dict(type="str"), expression=dict(type="str")),
         ),
+        runtime_platform=dict(
+            required=False,
+            default={"operatingSystemFamily": "LINUX", "cpuArchitecture": "X86_64"},
+            type="dict",
+            options=dict(
+                cpuArchitecture=dict(required=False, choices=["X86_64", "ARM64"]),
+                operatingSystemFamily=dict(
+                    required=False,
+                    choices=[
+                        "LINUX",
+                        "WINDOWS_SERVER_2019_FULL",
+                        "WINDOWS_SERVER_2019_CORE",
+                        "WINDOWS_SERVER_2022_FULL",
+                        "WINDOWS_SERVER_2022_CORE",
+                    ],
+                ),
+            ),
+        ),
     )
 
     module = AnsibleAWSModule(
@@ -1157,6 +1199,7 @@ def _task_definition_matches(
                     module.params["cpu"],
                     module.params["memory"],
                     module.params["placement_constraints"],
+                    module.params["runtime_platform"],
                 )
             results["changed"] = True
 


Test patch:
diff --git a/tests/integration/targets/ecs_cluster/tasks/20_ecs_service.yml b/tests/integration/targets/ecs_cluster/tasks/20_ecs_service.yml
--- a/tests/integration/targets/ecs_cluster/tasks/20_ecs_service.yml
+++ b/tests/integration/targets/ecs_cluster/tasks/20_ecs_service.yml
@@ -908,6 +908,65 @@
     started_by: ansible_user
   register: fargate_run_task_output_with_assign_ip
 
+- name: create task definition for ARM
+  ecs_taskdefinition:
+    containers: "{{ ecs_fargate_task_containers }}"
+    family: "{{ ecs_task_name }}-arm"
+    network_mode: awsvpc
+    launch_type: FARGATE
+    cpu: 512
+    memory: 1024
+    execution_role_arn: "{{ iam_execution_role.arn }}"
+    state: present
+    runtime_platform:
+      cpuArchitecture: "ARM64"
+      operatingSystemFamily: "LINUX"
+  vars:
+    ecs_task_host_port: 8080
+  register: fargate_arm_task_definition
+
+- name: check that initial task definition for ARM changes
+  assert:
+    that:
+      - fargate_arm_task_definition.changed
+
+- name: recreate task definition for ARM
+  ecs_taskdefinition:
+    containers: "{{ ecs_fargate_task_containers }}"
+    family: "{{ ecs_task_name }}-arm"
+    network_mode: awsvpc
+    launch_type: FARGATE
+    cpu: 512
+    memory: 1024
+    execution_role_arn: "{{ iam_execution_role.arn }}"
+    state: present
+    runtime_platform:
+      cpuArchitecture: "ARM64"
+      operatingSystemFamily: "LINUX"
+  vars:
+    ecs_task_host_port: 8080
+  register: fargate_arm_task_definition_again
+
+- name: check that task definition for ARM does not change
+  assert:
+    that:
+      - not fargate_arm_task_definition_again.changed
+
+- name: delete task definition for ARM
+  ecs_taskdefinition:
+    containers: "{{ ecs_fargate_task_containers }}"
+    family: "{{ ecs_task_name }}-arm"
+    network_mode: awsvpc
+    launch_type: FARGATE
+    cpu: 512
+    memory: 1024
+    execution_role_arn: "{{ iam_execution_role.arn }}"
+    state: present
+    runtime_platform:
+      cpuArchitecture: "ARM64"
+      operatingSystemFamily: "LINUX"
+  vars:
+    ecs_task_host_port: 8080
 
 # ============================================================
 # End tests for Fargate