Skip to content

Resource: awsEcsTaskSet

Provides an ECS task set - effectively a task that is expected to run until an error occurs or a user terminates it (typically a webserver or a database).

See ECS Task Set section in AWS developer guide.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.ecsTaskSet.EcsTaskSet(this, "example", {
  cluster: "${aws_ecs_cluster.example.id}",
  loadBalancer: [
    {
      containerName: "mongo",
      containerPort: 8080,
      targetGroupArn: "${aws_lb_target_group.example.arn}",
    },
  ],
  service: "${aws_ecs_service.example.id}",
  taskDefinition: "${aws_ecs_task_definition.example.arn}",
});

Ignoring Changes to Scale

You can utilize the generic Terraform resource lifecycle configuration block with ignoreChanges to create an ECS service with an initial count of running instances, then ignore any changes to that count caused externally (e.g. Application Autoscaling).

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsEcsTaskSetExample = new aws.ecsTaskSet.EcsTaskSet(this, "example", {
  scale: {
    value: 50,
  },
});
awsEcsTaskSetExample.addOverride("lifecycle", [
  {
    ignore_changes: ["scale"],
  },
]);

Argument Reference

The following arguments are required:

  • service - (Required) The short name or ARN of the ECS service.
  • cluster - (Required) The short name or ARN of the cluster that hosts the service to create the task set in.
  • taskDefinition - (Required) The family and revision (family:revision) or full ARN of the task definition that you want to run in your service.

The following arguments are optional:

  • capacityProviderStrategy - (Optional) The capacity provider strategy to use for the service. Can be one or more. Defined below.
  • externalId - (Optional) The external ID associated with the task set.
  • forceDelete - (Optional) Whether to allow deleting the task set without waiting for scaling down to 0. You can force a task set to delete even if it's in the process of scaling a resource. Normally, Terraform drains all the tasks before deleting the task set. This bypasses that behavior and potentially leaves resources dangling.
  • launchType - (Optional) The launch type on which to run your service. The valid values are ec2, fargate, and external. Defaults to ec2.
  • loadBalancer - (Optional) Details on load balancers that are used with a task set. Detailed below.
  • platformVersion - (Optional) The platform version on which to run your service. Only applicable for launchType set to fargate. Defaults to latest. More information about Fargate platform versions can be found in the AWS ECS User Guide.
  • networkConfiguration - (Optional) The network configuration for the service. This parameter is required for task definitions that use the awsvpc network mode to receive their own Elastic Network Interface, and it is not supported for other network modes. Detailed below.
  • scale - (Optional) A floating-point percentage of the desired number of tasks to place and keep running in the task set. Detailed below.
  • serviceRegistries - (Optional) The service discovery registries for the service. The maximum number of serviceRegistries blocks is 1. Detailed below.
  • tags - (Optional) A map of tags to assign to the file system. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level. If you have set copyTagsToBackups to true, and you specify one or more tags, no existing file system tags are copied from the file system to the backup.
  • waitUntilStable - (Optional) Whether terraform should wait until the task set has reached STEADY_STATE.
  • waitUntilStableTimeout - (Optional) Wait timeout for task set to reach STEADY_STATE. Valid time units include ns, us (or µs), ms, s, m, and h. Default 10M.

capacityProviderStrategy

The capacityProviderStrategy configuration block supports the following:

  • capacityProvider - (Required) The short name or full Amazon Resource Name (ARN) of the capacity provider.
  • weight - (Required) The relative percentage of the total number of launched tasks that should use the specified capacity provider.
  • base - (Optional) The number of tasks, at a minimum, to run on the specified capacity provider. Only one capacity provider in a capacity provider strategy can have a base defined.

loadBalancer

The loadBalancer configuration block supports the following:

  • containerName - (Required) The name of the container to associate with the load balancer (as it appears in a container definition).
  • loadBalancerName - (Optional, Required for ELB Classic) The name of the ELB (Classic) to associate with the service.
  • targetGroupArn - (Optional, Required for ALB/NLB) The ARN of the Load Balancer target group to associate with the service.
  • containerPort - (Optional) The port on the container to associate with the load balancer. Defaults to 0 if not specified.

\~> Note: Specifying multiple loadBalancer configurations is still not supported by AWS for ECS task set.

networkConfiguration

The networkConfiguration configuration block supports the following:

  • subnets - (Required) The subnets associated with the task or service. Maximum of 16.
  • securityGroups - (Optional) The security groups associated with the task or service. If you do not specify a security group, the default security group for the VPC is used. Maximum of 5.
  • assignPublicIp - (Optional) Whether to assign a public IP address to the ENI (fargate launch type only). Valid values are true or false. Default false.

For more information, see Task Networking.

scale

The scale configuration block supports the following:

  • unit - (Optional) The unit of measure for the scale value. Default: percent.
  • value - (Optional) The value, specified as a percent total of a service's desiredCount, to scale the task set. Defaults to 0 if not specified. Accepted values are numbers between 0.0 and 100.0.

serviceRegistries

serviceRegistries support the following:

  • registryArn - (Required) The ARN of the Service Registry. The currently supported service registry is Amazon Route 53 Auto Naming Service(awsServiceDiscoveryService resource). For more information, see Service.
  • port - (Optional) The port value used if your Service Discovery service specified an SRV record.
  • containerPort - (Optional) The port value, already specified in the task definition, to be used for your service discovery service.
  • containerName - (Optional) The container name value, already specified in the task definition, to be used for your service discovery service.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • id - The taskSetId, service and cluster separated by commas (,).
  • arn - The Amazon Resource Name (ARN) that identifies the task set.
  • stabilityStatus - The stability status. This indicates whether the task set has reached a steady state.
  • status - The status of the task set.
  • tagsAll - A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.
  • taskSetId - The ID of the task set.

Import

ECS Task Sets can be imported via the taskSetId, service, and cluster separated by commas (,) e.g.

$ terraform import aws_ecs_task_set.example ecs-svc/7177320696926227436,arn:aws:ecs:us-west-2:123456789101:service/example/example-1234567890,arn:aws:ecs:us-west-2:123456789101:cluster/example