When creating an ECS task with terraform it is missing required attributes for pulling image from ECR

Solution for When creating an ECS task with terraform it is missing required attributes for pulling image from ECR
is Given Below:

When I try to create an AWS ECS task with terraform ecs_task_definition the task is created successfully but it is missing some required attributes (com.amazonaws.ecs.capability.ecr-auth, ecs.capability.execution-role-ecr-pull
) which prevents from the container to pull the image from ECR.

When I create the task using AWS CLI with the same parameters (including the same roles for ‘execution role’ and ‘task role’) it do add all required attributes and the container successfully pull the image from ECR.

The container definition json is:

{
    "containerDefinitions": [
        {
            "name": "container_main_env-test1",
            "image": "586289480321.dkr.ecr.eu-west-1.amazonaws.com/XXXX-saas:latest",
            "cpu": 1024,
            "memory": 5000,
            "essential": true,
            "logConfiguration": {
                "logDriver": "awslogs",
                "options": {
                    "awslogs-group": "/ecs/XXXX-test1",
                    "awslogs-region": "eu-west-1",
                    "awslogs-stream-prefix": "ecs"
                }
            },
            "portMappings": [
                {
                    "containerPort": 80,
                    "hostPort": 80
                }
            ]
        }
    ]
}

The task definition is:

resource "aws_ecs_task_definition" "XXXX_task_definition" {
  family        = var.name
  task_role_arn = aws_iam_role.XXXX_ecs_task_role.arn
  execution_role_arn    = "arn:aws:iam::586289480321:role/ecsTaskExecutionRole"
  container_definitions = var.container_definition_content
}

The json above is passed as parameter to this definition on ‘var.container_definition_content’

Is there a known bug about it or some tweak that I am missing?

Thanks,
Ronen