--- subcategory: "ECS (Elastic Container)" layout: "aws" page_title: "AWS: aws_ecs_task_definition" description: |- Manages a revision of an ECS task definition. --- # Resource: aws_ecs_task_definition Manages a revision of an ECS task definition to be used in `aws_ecs_service`. ## Example Usage ### Basic Example ```terraform resource "aws_ecs_task_definition" "service" { family = "service" container_definitions = jsonencode([ { name = "first" image = "service-first" cpu = 10 memory = 512 essential = true portMappings = [ { containerPort = 80 hostPort = 80 } ] }, { name = "second" image = "service-second" cpu = 10 memory = 256 essential = true portMappings = [ { containerPort = 443 hostPort = 443 } ] } ]) volume { name = "service-storage" host_path = "/ecs/service-storage" } placement_constraints { type = "memberOf" expression = "attribute:ecs.availability-zone in [us-west-2a, us-west-2b]" } } ``` ### With App Mesh Proxy ```terraform resource "aws_ecs_task_definition" "service" { family = "service" container_definitions = file("task-definitions/service.json") proxy_configuration { type = "APPMESH" container_name = "applicationContainerName" properties = { AppPorts = "8080" EgressIgnoredIPs = "169.254.170.2,169.254.169.254" IgnoredUID = "1337" ProxyEgressPort = 15001 ProxyIngressPort = 15000 } } } ``` ### Example Using `docker_volume_configuration` ```terraform resource "aws_ecs_task_definition" "service" { family = "service" container_definitions = file("task-definitions/service.json") volume { name = "service-storage" docker_volume_configuration { scope = "shared" autoprovision = true driver = "local" driver_opts = { "type" = "nfs" "device" = "${aws_efs_file_system.fs.dns_name}:/" "o" = "addr=${aws_efs_file_system.fs.dns_name},rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport" } } } } ``` ### Example Using `efs_volume_configuration` ```terraform resource "aws_ecs_task_definition" "service" { family = "service" container_definitions = file("task-definitions/service.json") volume { name = "service-storage" efs_volume_configuration { file_system_id = aws_efs_file_system.fs.id root_directory = "/opt/data" transit_encryption = "ENABLED" transit_encryption_port = 2999 authorization_config { access_point_id = aws_efs_access_point.test.id iam = "ENABLED" } } } } ``` ### Example Using `fsx_windows_file_server_volume_configuration` ```terraform resource "aws_ecs_task_definition" "service" { family = "service" container_definitions = file("task-definitions/service.json") volume { name = "service-storage" fsx_windows_file_server_volume_configuration { file_system_id = aws_fsx_windows_file_system.test.id root_directory = "\\data" authorization_config { credentials_parameter = aws_secretsmanager_secret_version.test.arn domain = aws_directory_service_directory.test.name } } } } resource "aws_secretsmanager_secret_version" "test" { secret_id = aws_secretsmanager_secret.test.id secret_string = jsonencode({ username : "admin", password : aws_directory_service_directory.test.password }) } ``` ### Example Using `container_definitions` ```terraform resource "aws_ecs_task_definition" "test" { family = "test" container_definitions = < **NOTE:** Proper escaping is required for JSON field values containing quotes (`"`) such as `environment` values. If directly setting the JSON, they should be escaped as `\"` in the JSON, e.g., `"value": "I \"love\" escaped quotes"`. If using a Terraform variable value, they should be escaped as `\\\"` in the variable, e.g., `value = "I \\\"love\\\" escaped quotes"` in the variable and `"value": "${var.myvariable}"` in the JSON. ~> **Note:** Fault injection only works with tasks using the `awsvpc` or `host` network modes. Fault injection isn't available on Windows. ### `volume` Block * `configure_at_launch` - (Optional) Whether the volume should be configured at launch time. This is used to create Amazon EBS volumes for standalone tasks or tasks created as part of a service. Each task definition revision may only have one volume configured at launch in the volume configuration. * `docker_volume_configuration` - (Optional) Configuration block to configure a [docker volume](#docker_volume_configuration-block). Detailed below. * `efs_volume_configuration` - (Optional) Configuration block for an [EFS volume](#efs_volume_configuration-block). Detailed below. * `fsx_windows_file_server_volume_configuration` - (Optional) Configuration block for an [FSx Windows File Server volume](#fsx_windows_file_server_volume_configuration-block). Detailed below. * `host_path` - (Optional) Path on the host container instance that is presented to the container. If not set, ECS will create a nonpersistent data volume that starts empty and is deleted after the task has finished. * `name` - (Required) Name of the volume. This name is referenced in the `sourceVolume` parameter of container definition in the `mountPoints` section. * `s3files_volume_configuration` - (Optional) Configuration block for an [S3 Files volume](#s3files_volume_configuration-block). Detailed below. ### `docker_volume_configuration` Block For more information, see [Specifying a Docker volume in your Task Definition Developer Guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-volumes.html#specify-volume-config) * `autoprovision` - (Optional) If this value is `true`, the Docker volume is created if it does not already exist. *Note*: This field is only used if the scope is `shared`. * `driver` - (Optional) Docker volume driver to use. The driver value must match the driver name provided by Docker because it is used for task placement. * `driver_opts` - (Optional) Map of Docker driver specific options. * `labels` - (Optional) Map of custom metadata to add to your Docker volume. * `scope` - (Optional) Scope for the Docker volume, which determines its lifecycle, either `task` or `shared`. Docker volumes that are scoped to a `task` are automatically provisioned when the task starts and destroyed when the task stops. Docker volumes that are scoped as `shared` persist after the task stops. ### `efs_volume_configuration` Block For more information, see [Specifying an EFS volume in your Task Definition Developer Guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/efs-volumes.html#specify-efs-config) * `authorization_config` - (Optional) Configuration block for [authorization](#efs_volume_configurationauthorization_config-block) for the Amazon EFS file system. Detailed below. * `file_system_id` - (Required) ID of the EFS File System. * `root_directory` - (Optional) Directory within the Amazon EFS file system to mount as the root directory inside the host. If this parameter is omitted, the root of the Amazon EFS volume will be used. Specifying / will have the same effect as omitting this parameter. This argument is ignored when using `authorization_config`. * `transit_encryption` - (Optional) Whether or not to enable encryption for Amazon EFS data in transit between the Amazon ECS host and the Amazon EFS server. Transit encryption must be enabled if Amazon EFS IAM authorization is used. Valid values: `ENABLED`, `DISABLED`. If this parameter is omitted, the default value of `DISABLED` is used. * `transit_encryption_port` - (Optional) Port to use for transit encryption. If you do not specify a transit encryption port, it will use the port selection strategy that the Amazon EFS mount helper uses. ### `runtime_platform` Block * `cpu_architecture` - (Optional) Must be set to either `X86_64` or `ARM64`; see [CPU architecture](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#runtime-platform) * `operating_system_family` - (Optional) If the `requires_compatibilities` is `FARGATE` this field is required; must be set to a valid option from the [operating system family in the runtime platform](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#runtime-platform) setting #### `efs_volume_configuration.authorization_config` Block * `access_point_id` - (Optional) Access point ID to use. If an access point is specified, the root directory value will be relative to the directory set for the access point. If specified, transit encryption must be enabled in the EFSVolumeConfiguration. * `iam` - (Optional) Whether or not to use the Amazon ECS task IAM role defined in a task definition when mounting the Amazon EFS file system. If enabled, transit encryption must be enabled in the EFSVolumeConfiguration. Valid values: `ENABLED`, `DISABLED`. If this parameter is omitted, the default value of `DISABLED` is used. ### `fsx_windows_file_server_volume_configuration` Block For more information, see [Specifying an FSx Windows File Server volume in your Task Definition Developer Guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/tutorial-wfsx-volumes.html) * `authorization_config` - (Required) Configuration block for [authorization](#fsx_windows_file_server_volume_configurationauthorization_config-block) for the Amazon FSx for Windows File Server file system detailed below. * `file_system_id` - (Required) Amazon FSx for Windows File Server file system ID to use. * `root_directory` - (Required) Directory within the Amazon FSx for Windows File Server file system to mount as the root directory inside the host. #### `fsx_windows_file_server_volume_configuration.authorization_config` Block * `credentials_parameter` - (Required) Authorization credential option to use. The authorization credential options can be provided using either the ARN of an AWS Secrets Manager secret or AWS Systems Manager Parameter Store parameter. The ARNs refer to the stored credentials. * `domain` - (Required) Fully qualified domain name hosted by an AWS Directory Service Managed Microsoft AD (Active Directory) or self-hosted AD on Amazon EC2. ### `s3files_volume_configuration` Block For more information, see [Mounting S3 file systems on Amazon ECS](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-files-mounting-ecs.html). * `access_point_arn` - (Optional) Full ARN of the S3 Files access point to use. If configured, `root_directory` must either be omitted or set to `"/"`. * `file_system_arn` - (Required) Full ARN of the S3 Files file system to mount. * `root_directory` - (Optional) Directory within the Amazon S3 Files file system to mount as the root directory. * `transit_encryption_port` - (Optional) Port to use for sending encrypted data between the ECS host and the S3 Files file system. ### `placement_constraints` Block * `expression` - (Optional) Cluster Query Language expression to apply to the constraint. For more information, see [Cluster Query Language in the Amazon EC2 Container Service Developer Guide](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html). * `type` - (Required) Type of constraint. Use `memberOf` to restrict selection to a group of valid candidates. Note that `distinctInstance` is not supported in task definitions. ### `proxy_configuration` Block * `container_name` - (Required) Name of the container that will serve as the App Mesh proxy. * `properties` - (Optional) Set of network configuration parameters to provide the Container Network Interface (CNI) plugin, specified a key-value mapping. * `type` - (Optional) Proxy type. The default value is `APPMESH`. The only supported value is `APPMESH`. ### `ephemeral_storage` Block * `size_in_gib` - (Required) Total amount, in GiB, of ephemeral storage to set for the task. The minimum supported value is `21` GiB and the maximum supported value is `200` GiB. ## Attribute Reference This resource exports the following attributes in addition to the arguments above: * `arn` - Full ARN of the Task Definition (including both `family` and `revision`). * `arn_without_revision` - ARN of the Task Definition with the trailing `revision` removed. This may be useful for situations where the latest task definition is always desired. If a revision isn't specified, the latest ACTIVE revision is used. See the [AWS documentation](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_StartTask.html#ECS-StartTask-request-taskDefinition) for details. * `revision` - Revision of the task in a particular family. * `tags_all` - Map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). ## Import In Terraform v1.12.0 and later, the [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used with the `identity` attribute. For example: ```terraform import { to = aws_ecs_task_definition.example identity = { family = "mytaskfamily" revision = 123 } } resource "aws_ecs_task_definition" "example" { ### Configuration omitted for brevity ### } ``` ### Identity Schema #### Required * `family` (String) The unique name for your task definition. * `revision` (Integer) The revision of the task in a particular family. #### Optional * `account_id` (String) AWS Account where this resource is managed. * `region` (String) Region where this resource is managed. In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import ECS Task Definitions using their ARNs. For example: ```terraform import { to = aws_ecs_task_definition.example id = "arn:aws:ecs:us-east-1:012345678910:task-definition/mytaskfamily:123" } ``` Using `terraform import`, import ECS Task Definitions using their ARNs. For example: ```console % terraform import aws_ecs_task_definition.example arn:aws:ecs:us-east-1:012345678910:task-definition/mytaskfamily:123 ```