[
  {
    "name": "${service_name}",
    "image": "${docker_image}",
    "cpu": ${application_task_cpu},
    "memory": ${application_task_memory},
    "essential": true,
    "dependsOn": [
%{ if is_defender_enabled  }
      {
        "condition": "HEALTHY",
        "containerName": "TwistlockDefender"
      },
%{ endif }
      {
        "containerName": "datadog-agent",
        "condition": "START"
      }
    ],
    "dockerLabels": ${jsonencode(docker_labels)},
    "mountPoints": ${jsonencode(mount_points)},
    "healthCheck": {
      "command": ${jsonencode("${health_check_command}")},
      "interval": ${health_check_interval},
      "timeout": ${health_check_timeout},
      "retries": 3,
      "startPeriod": ${container_start_period_seconds}
    },
    "portMappings": ${jsonencode("${port_mappings}")},
    "volumesFrom": [
%{ if is_defender_enabled }
      {
        "readOnly": false,
        "sourceContainer": "TwistlockDefender"
      }
%{ endif }
    ],
    "logConfiguration": {
      "logDriver": "awsfirelens",
      "options": ${jsonencode("${log_configuration_options}")},
      "secretOptions": [{
        "name": "apikey",
        "valueFrom": "${datadog_api_key}"
      }]
    },
    "ulimits": [
      {
        "name": "nofile",
        "softLimit": ${ulimit_nofile_soft_limit},
        "hardLimit": ${ulimit_nofile_hard_limit}
      }
    ],
    "environment": [
%{ if is_defender_enabled }
      {
        "name": "TW_IMAGE_NAME",
        "value": "${docker_image}"
      },
      {
        "name": "TW_CONTAINER_NAME",
        "value": "${service_name}"
      },
      {
        "name": "DEFENDER_TYPE",
        "value": "fargate"
      },
      {
        "name": "FARGATE_TASK",
        "value": "${environment}-${service_name}"
      },
      {
        "name": "FILESYSTEM_MONITORING",
        "value": "${defender_filesystem_monitoring_enabled}"
      },
      {
        "name": "FIPS_ENABLED",
        "value": "false"
      },
%{ endif }
      ${environment_variables}
    ],
%{ if is_defender_enabled }
    "linuxParameters": {
      "capabilities": {
        "add": [
          "SYS_PTRACE"
        ],
        "drop": []
      }
    },
%{ endif }
    "secrets": [
      ${secrets}
    ],
    "systemControls": [],
    "versionConsistency": "${version_consistency}"
  },
%{ if is_defender_enabled }
  {
    "name": "TwistlockDefender",
    "image": "${defender_image}",
    "cpu": ${defender_task_cpu},
    "memory": ${defender_task_memory},
    "essential": true,
    "entryPoint": [
      "/usr/local/bin/defender",
      "fargate",
      "sidecar"
    ],
    "dockerLabels": {
      "Environment": "${environment}"
    },
    "portMappings": [],
    "mountPoints": [],
    "healthCheck": {
      "command": [
        "/usr/local/bin/defender",
        "fargate",
        "healthcheck"
      ],
      "interval": 5,
      "retries": 3,
      "startPeriod": 1,
      "timeout": 5
    },
    "volumesFrom": [],
    "logConfiguration": null,
    "environment": [
      {
        "name": "INSTALL_BUNDLE",
        "value": "eyJzZWNyZXRzIjp7InNlcnZpY2UtcGFyYW1ldGVyIjoieTl0RDdmazJZdVEvNkN4TWVIcldsQXFpSmFPMldocXhtbVdheFE3bFAwNFVMaFYxYXhZcVJ6U09HUzBzZnlrMU9NT1FwaWxhU2RFYWN0TVdKQ0FzZXc9PSJ9LCJnbG9iYWxQcm94eU9wdCI6eyJodHRwUHJveHkiOiIiLCJub1Byb3h5IjoiIiwiY2EiOiIiLCJ1c2VyIjoiIiwicGFzc3dvcmQiOnsiZW5jcnlwdGVkIjoiIn19LCJjdXN0b21lcklEIjoidXMtMi0xNTgyNjI0OTMiLCJhcGlLZXkiOiJWdGlsbmtHOUFObnphYlZMdkF6ZmZWU0htRVRWdDI3bHZNSUlnVzNUTy9ReSsvc2UwRGFub3MwQTQwUXpKbTZMaS9NZHcrSys0VHJWbnhjZW1DaG9IQT09IiwibWljcm9zZWdDb21wYXRpYmxlIjpmYWxzZX0="
      },
      {
        "name": "DEFENDER_TYPE",
        "value": "fargate"
      },
      {
        "name": "FARGATE_TASK",
        "value": "${environment}-${service_name}"
      },
      {
        "name": "WS_ADDRESS",
        "value": "${defender_ws_address}"
      },
      {
        "name": "FILESYSTEM_MONITORING",
        "value": "${defender_filesystem_monitoring_enabled}"
      },
      {
        "name": "FIPS_ENABLED",
        "value": "false"
      }
    ],
    "secrets": [],
    "systemControls": [],
    "versionConsistency": "${version_consistency}"
  },
%{ endif }
  {
    "name": "datadog-agent",
    "image": "${datadog_image}",
    "cpu": ${datadog_task_cpu},
    "memory": ${datadog_task_memory},
    "essential": false,
    "dockerLabels": {
      "Environment": "${environment}"
    },
    "portMappings": [
      {
        "hostPort": 4317,
        "containerPort": 4317,
        "protocol": "tcp"
      },
      {
        "hostPort": 4318,
        "containerPort": 4318,
        "protocol": "tcp"
      },
      {
        "hostPort": 8126,
        "containerPort": 8126,
        "protocol": "tcp"
      }
    ],
    "mountPoints": [],
    "volumesFrom": [],
    "logConfiguration": {
      "logDriver": "awslogs",
      "options": {
        "awslogs-create-group": "true",
        "awslogs-group": "${environment}-${service_name}-datadog-agent",
        "awslogs-region": "${aws_region}",
        "awslogs-stream-prefix": "${environment}-${service_name}-datadog-agent"
      }
    },
    "environment": [
      ${datadog_agent_environment_variables}
    ],
    "secrets": [
      {
        "name": "DD_API_KEY",
        "valueFrom": "${datadog_api_key}"
      }
    ],
    "systemControls": [],
    "versionConsistency": "${version_consistency}"
  },
  {
    "name": "fluentbit-datadog",
    "image": "${fluentbit_image}",
    "cpu": ${fluentbit_task_cpu},
    "memory": ${fluentbit_task_memory},
    "essential": false,
    "dockerLabels": {
      "Environment": "${environment}"
    },
    "firelensConfiguration": {
      "type": "fluentbit",
      "options": ${jsonencode("${firelens_configuration_options}")}
    },
    "portMappings": [],
    "mountPoints": [],
    "volumesFrom": [],
    "logConfiguration": {
      "logDriver": "awslogs",
      "options": {
        "awslogs-create-group": "true",
        "awslogs-group": "${environment}-${service_name}-fluentbit",
        "awslogs-region": "${aws_region}",
        "awslogs-stream-prefix": "${environment}-${service_name}-fluentbit"
      }
    },
    "user": "0",
    "environment": [
      {
        "name": "FLB_LOG_LEVEL",
        "value": "${log_router_log_level}"
      }
    ],
    "secrets": [],
    "systemControls": [],
    "versionConsistency": "${version_consistency}"
  }
]
