How do I add ulimits to an aws_ecs_task_definition?

Originally from a tweet!

How do I add ulimits to an aws_ecs_task_definition?

You can add ulimits as part of container_definitions. ECS Task Definitions requests a JSON definition for each container.

For example:

locals {
  container_definitions = [
    {
      name   = "my_container"
      image  = "nginx"
      cpu    = 1024
      memory = 2048
      ulimits = [
        {
          name      = "nofile"
          hardLimit = 65535
          softLimit = 65535
        }
      ]
    }
  ]
}


resource "aws_ecs_task_definition" "cfola_worker" {
  family                = "${var.stage}-cfola-worker"
  container_definitions = jsonencode(local.container_definitions)
}