--- subcategory: "ECS (Elastic Container)" layout: "aws" page_title: "AWS: aws_ecs_service" description: |- Provides an ECS service. --- # Resource: aws_ecs_service -> **Note:** To prevent a race condition during service deletion, make sure to set `depends_on` to the related `aws_iam_role_policy`; otherwise, the policy may be destroyed too soon and the ECS service will then get stuck in the `DRAINING` state. Provides an ECS service - 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 Services section in AWS developer guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_services.html). ## Example Usage ```terraform resource "aws_ecs_service" "mongo" { name = "mongodb" cluster = aws_ecs_cluster.foo.id task_definition = aws_ecs_task_definition.mongo.arn desired_count = 3 iam_role = aws_iam_role.foo.arn depends_on = [aws_iam_role_policy.foo] ordered_placement_strategy { type = "binpack" field = "cpu" } load_balancer { target_group_arn = aws_lb_target_group.foo.arn container_name = "mongo" container_port = 8080 } placement_constraints { type = "memberOf" expression = "attribute:ecs.availability-zone in [us-west-2a, us-west-2b]" } } ``` ### Ignoring Changes to Desired Count You can utilize the generic Terraform resource [lifecycle configuration block](https://www.terraform.io/docs/configuration/meta-arguments/lifecycle.html) with `ignore_changes` to create an ECS service with an initial count of running instances, then ignore any changes to that count caused externally (e.g., Application Auto Scaling). ```terraform resource "aws_ecs_service" "example" { # ... other configurations ... # Example: Create service with 2 instances to start desired_count = 2 # Optional: Allow external changes without Terraform plan difference lifecycle { ignore_changes = [desired_count] } } ``` ### Daemon Scheduling Strategy ```terraform resource "aws_ecs_service" "bar" { name = "bar" cluster = aws_ecs_cluster.foo.id task_definition = aws_ecs_task_definition.bar.arn scheduling_strategy = "DAEMON" } ``` ### CloudWatch Deployment Alarms ```terraform resource "aws_ecs_service" "example" { name = "example" cluster = aws_ecs_cluster.example.id alarms { enable = true rollback = true alarm_names = [ aws_cloudwatch_metric_alarm.example.alarm_name ] } } ``` ### External Deployment Controller ```terraform resource "aws_ecs_service" "example" { name = "example" cluster = aws_ecs_cluster.example.id deployment_controller { type = "EXTERNAL" } } ``` ### Blue/Green Deployment with SIGINT Rollback ```terraform resource "aws_ecs_service" "example" { name = "example" cluster = aws_ecs_cluster.example.id # ... other configurations ... deployment_configuration { strategy = "BLUE_GREEN" } sigint_rollback = true wait_for_steady_state = true } ``` ### Linear Deployment Strategy ```terraform resource "aws_ecs_service" "example" { name = "example" cluster = aws_ecs_cluster.example.id # ... other configurations ... deployment_configuration { strategy = "LINEAR" bake_time_in_minutes = 10 linear_configuration { step_percent = 25.0 step_bake_time_in_minutes = 5 } } } ``` ### Canary Deployment Strategy ```terraform resource "aws_ecs_service" "example" { name = "example" cluster = aws_ecs_cluster.example.id # ... other configurations ... deployment_configuration { strategy = "CANARY" bake_time_in_minutes = 15 canary_configuration { canary_percent = 10.0 canary_bake_time_in_minutes = 5 } } } ``` ### Redeploy Service On Every Apply The key used with `triggers` is arbitrary. ```terraform resource "aws_ecs_service" "example" { # ... other configurations ... force_new_deployment = true triggers = { redeployment = plantimestamp() } } ``` ### Service Connect with Access Logs ```terraform resource "aws_ecs_service" "example" { name = "example" cluster = aws_ecs_cluster.example.id task_definition = aws_ecs_task_definition.example.arn desired_count = 1 service_connect_configuration { enabled = true namespace = aws_service_discovery_http_namespace.example.arn log_configuration { log_driver = "awslogs" options = { "awslogs-group" = aws_cloudwatch_log_group.example.name "awslogs-region" = data.aws_region.current.region "awslogs-stream-prefix" = "service-connect" } } access_log_configuration { format = "TEXT" include_query_parameters = "ENABLED" } service { port_name = "http" discovery_name = "example" client_alias { dns_name = "example" port = 8080 } } } } resource "aws_cloudwatch_log_group" "example" { name = "/ecs/example/service-connect" } data "aws_region" "current" {} ``` ## Argument Reference The following arguments are required: * `name` - (Required) Name of the service (up to 255 letters, numbers, hyphens, and underscores) The following arguments are optional: * `alarms` - (Optional) Information about the CloudWatch alarms. [See below](#alarms-block). * `availability_zone_rebalancing` - (Optional) ECS automatically redistributes tasks within a service across Availability Zones (AZs) to mitigate the risk of impaired application availability due to underlying infrastructure failures and task lifecycle activities. The valid values are `ENABLED` and `DISABLED`. When creating a new service, if no value is specified, it defaults to `ENABLED` if the service is compatible with AvailabilityZoneRebalancing. When updating an existing service, if no value is specified it defaults to the existing service's AvailabilityZoneRebalancing value. If the service never had an AvailabilityZoneRebalancing value set, Amazon ECS treats this as `DISABLED`. * `capacity_provider_strategy` - (Optional) Capacity provider strategies to use for the service. Can be one or more. Updating this argument requires `force_new_deployment = true`. [See below](#capacity_provider_strategy-block). Conflicts with `launch_type`. * `cluster` - (Optional) ARN of an ECS cluster. * `deployment_circuit_breaker` - (Optional) Configuration block for deployment circuit breaker. [See below](#deployment_circuit_breaker-block). * `deployment_configuration` - (Optional) Configuration block for deployment settings. [See below](#deployment_configuration-block). * `deployment_controller` - (Optional) Configuration block for deployment controller configuration. [See below](#deployment_controller-block). * `deployment_maximum_percent` - (Optional) Upper limit (as a percentage of the service's desiredCount) of the number of running tasks that can be running in a service during a deployment. Not valid when using the `DAEMON` scheduling strategy. * `deployment_minimum_healthy_percent` - (Optional) Lower limit (as a percentage of the service's desiredCount) of the number of running tasks that must remain running and healthy in a service during a deployment. * `desired_count` - (Optional) Number of instances of the task definition to place and keep running. Defaults to 0. Do not specify if using the `DAEMON` scheduling strategy. * `enable_ecs_managed_tags` - (Optional) Whether to enable Amazon ECS managed tags for the tasks within the service. * `enable_execute_command` - (Optional) Whether to enable Amazon ECS Exec for the tasks within the service. * `force_delete` - (Optional) Enable to delete a service even if it wasn't scaled down to zero tasks. It's only necessary to use this if the service uses the `REPLICA` scheduling strategy. * `force_new_deployment` - (Optional) Enable to force a new task deployment of the service. This can be used to update tasks to use a newer Docker image with same image/tag combination (e.g., `myimage:latest`), roll Fargate tasks onto a newer platform version, or immediately deploy `ordered_placement_strategy` and `placement_constraints` updates. * `health_check_grace_period_seconds` - (Optional) Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 2147483647. Only valid for services configured to use load balancers. * `iam_role` - (Optional) ARN of the IAM role that allows Amazon ECS to make calls to your load balancer on your behalf. This parameter is required if you are using a load balancer with your service, but only if your task definition does not use the `awsvpc` network mode. If using `awsvpc` network mode, do not specify this role. If your account has already created the Amazon ECS service-linked role, that role is used by default for your service unless you specify a role here. * `launch_type` - (Optional) Launch type on which to run your service. The valid values are `EC2`, `FARGATE`, and `EXTERNAL`. Defaults to `EC2`. Conflicts with `capacity_provider_strategy`. * `load_balancer` - (Optional) Configuration block for load balancers. [See below](#load_balancer-block). * `network_configuration` - (Optional) 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. [See below](#network_configuration-block). * `ordered_placement_strategy` - (Optional) Service level strategy rules that are taken into consideration during task placement. List from top to bottom in order of precedence. Updates to this configuration will take effect next task deployment unless `force_new_deployment` is enabled. The maximum number of `ordered_placement_strategy` blocks is `5`. [See below](#ordered_placement_strategy-block). * `placement_constraints` - (Optional) Rules that are taken into consideration during task placement. Updates to this configuration will take effect next task deployment unless `force_new_deployment` is enabled. Maximum number of `placement_constraints` is `10`. [See below](#placement_constraints-block). * `platform_version` - (Optional) Platform version on which to run your service. Only applicable for `launch_type` set to `FARGATE`. Defaults to `LATEST`. More information about Fargate platform versions can be found in the [AWS ECS User Guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/platform_versions.html). * `propagate_tags` - (Optional) Whether to propagate the tags from the task definition or the service to the tasks. The valid values are `SERVICE` and `TASK_DEFINITION`. * `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference). * `scheduling_strategy` - (Optional) Scheduling strategy to use for the service. The valid values are `REPLICA` and `DAEMON`. Defaults to `REPLICA`. Note that [*Tasks using the Fargate launch type or the `CODE_DEPLOY` or `EXTERNAL` deployment controller types don't support the `DAEMON` scheduling strategy*](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_CreateService.html). * `service_connect_configuration` - (Optional) ECS Service Connect configuration for this service to discover and connect to services, and be discovered by, and connected from, other services within a namespace. [See below](#service_connect_configuration-block). * `service_registries` - (Optional) Service discovery registries for the service. The maximum number of `service_registries` blocks is `1`. [See below](#service_registries-block). * `sigint_rollback` - (Optional) Whether to enable graceful termination of deployments using SIGINT signals. When enabled, allows customers to safely cancel an in-progress deployment and automatically trigger a rollback to the previous stable state. Defaults to `false`. Only applicable when using `ECS` deployment controller and requires `wait_for_steady_state = true`. * `tags` - (Optional) Key-value map of resource tags. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. * `task_definition` - (Optional) Family and revision (`family:revision`) or full ARN of the task definition that you want to run in your service. Required unless using the `EXTERNAL` deployment controller. If a revision is not specified, the latest `ACTIVE` revision is used. * `triggers` - (Optional) Map of arbitrary keys and values that, when changed, will trigger an in-place update (redeployment). Useful with `plantimestamp()`. See example above. * `volume_configuration` - (Optional) Configuration for a volume specified in the task definition as a volume that is configured at launch time. Currently, the only supported volume type is an Amazon EBS volume. [See below](#volume_configuration-block). * `vpc_lattice_configurations` - (Optional) VPC Lattice configuration for your service that allows Lattice to connect, secure, and monitor your service across multiple accounts and VPCs. [See below](#vpc_lattice_configurations-block). * `wait_for_steady_state` - (Optional) If `true`, Terraform will wait for the service to reach a steady state (like [`aws ecs wait services-stable`](https://docs.aws.amazon.com/cli/latest/reference/ecs/wait/services-stable.html)) before continuing. Default `false`. ### `alarms` Block The `alarms` configuration block supports the following: * `alarm_names` - (Required) One or more CloudWatch alarm names. * `enable` - (Required) Whether to use the CloudWatch alarm option in the service deployment process. * `rollback` - (Required) Whether to configure Amazon ECS to roll back the service if a service deployment fails. If rollback is used, when a service deployment fails, the service is rolled back to the last deployment that completed successfully. ### `volume_configuration` Block The `volume_configuration` configuration block supports the following: * `managed_ebs_volume` - (Required) Configuration for the Amazon EBS volume that Amazon ECS creates and manages on your behalf. [See below](#managed_ebs_volume-block). * `name` - (Required) Name of the volume. ### `vpc_lattice_configurations` Block `vpc_lattice_configurations` supports the following: * `port_name` - (Required) Name of the port for a target group associated with the VPC Lattice configuration. * `role_arn` - (Required) ARN of the IAM role to associate with this volume. This is the Amazon ECS infrastructure IAM role that is used to manage your AWS infrastructure. * `target_group_arn` - (Required) Full ARN of the target group or groups associated with the VPC Lattice configuration. ### `managed_ebs_volume` Block The `managed_ebs_volume` configuration block supports the following: * `encrypted` - (Optional) Whether the volume should be encrypted. Default value is `true`. * `file_system_type` - (Optional) Linux filesystem type for the volume. For volumes created from a snapshot, same filesystem type must be specified that the volume was using when the snapshot was created. Valid values are `ext3`, `ext4`, `xfs`. Default value is `xfs`. * `iops` - (Optional) Number of I/O operations per second (IOPS). * `kms_key_id` - (Optional) ARN identifier of the Amazon Web Services KMS key to use for Amazon EBS encryption. * `role_arn` - (Required) Amazon ECS infrastructure IAM role that is used to manage your Amazon Web Services infrastructure. Recommended using the Amazon ECS-managed `AmazonECSInfrastructureRolePolicyForVolumes` IAM policy with this role. * `size_in_gb` - (Optional) Size of the volume in GiB. You must specify either a `size_in_gb` or a `snapshot_id`. You can optionally specify a volume size greater than or equal to the snapshot size. * `snapshot_id` - (Optional) Snapshot that Amazon ECS uses to create the volume. You must specify either a `size_in_gb` or a `snapshot_id`. * `tag_specifications` - (Optional) Tags to apply to the volume. [See below](#tag_specifications-block). * `throughput` - (Optional) Throughput to provision for a volume, in MiB/s, with a maximum of 1,000 MiB/s. * `volume_initialization_rate` - (Optional) Volume Initialization Rate in MiB/s. You must also specify a `snapshot_id`. * `volume_type` - (Optional) Volume type. ### `capacity_provider_strategy` Block The `capacity_provider_strategy` configuration block supports the following: * `base` - (Optional) 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. * `capacity_provider` - (Required) Short name of the capacity provider. * `weight` - (Optional) Relative percentage of the total number of launched tasks that should use the specified capacity provider. ### `deployment_configuration` Block The `deployment_configuration` configuration block supports the following: * `bake_time_in_minutes` - (Optional) Number of minutes to wait after a new deployment is fully provisioned before terminating the old deployment. Valid range: 0-1440 minutes. Used with `BLUE_GREEN`, `LINEAR`, and `CANARY` strategies. * `canary_configuration` - (Optional) Configuration block for canary deployment strategy. Required when `strategy` is set to `CANARY`. [See below](#canary_configuration-block). * `lifecycle_hook` - (Optional) Configuration block for lifecycle hooks that are invoked during deployments. [See below](#lifecycle_hook-block). * `linear_configuration` - (Optional) Configuration block for linear deployment strategy. Required when `strategy` is set to `LINEAR`. [See below](#linear_configuration-block). * `strategy` - (Optional) Type of deployment strategy. Valid values: `ROLLING`, `BLUE_GREEN`, `LINEAR`, `CANARY`. Default: `ROLLING`. ### `lifecycle_hook` Block The `lifecycle_hook` configuration block supports the following: * `hook_details` - (Optional) Custom parameters that Amazon ECS will pass to the hook target invocations (such as a Lambda function). * `hook_target_arn` - (Optional) ARN of the Lambda function to invoke for the lifecycle hook. Required when `target_type` is `AWS_LAMBDA`. Not used when `target_type` is `PAUSE`. * `lifecycle_stages` - (Required) Stages during the deployment when the hook should be invoked. Valid values: `RECONCILE_SERVICE`, `PRE_SCALE_UP`, `POST_SCALE_UP`, `TEST_TRAFFIC_SHIFT`, `POST_TEST_TRAFFIC_SHIFT`, `PRE_PRODUCTION_TRAFFIC_SHIFT`, `PRODUCTION_TRAFFIC_SHIFT`, `POST_PRODUCTION_TRAFFIC_SHIFT`. * `role_arn` - (Optional) ARN of the IAM role that grants the service permission to invoke the Lambda function. Required when `target_type` is `AWS_LAMBDA`. Not used when `target_type` is `PAUSE`. * `target_type` - (Optional) Type of hook target. Valid values: `AWS_LAMBDA`, `PAUSE`. Default: `AWS_LAMBDA`. `PAUSE` hooks cannot use the `TEST_TRAFFIC_SHIFT` or `PRODUCTION_TRAFFIC_SHIFT` lifecycle stages. * `timeout_configuration` - (Optional) Configuration block defining the timeout behavior for a `PAUSE` hook. Only valid when `target_type` is `PAUSE`. [See below](#timeout_configuration-block). ### `timeout_configuration` Block The `timeout_configuration` configuration block supports the following: * `action` - (Optional) Action ECS takes when the pause hook times out. Valid values: `ROLLBACK`, `CONTINUE`. Default: `ROLLBACK`. * `timeout_in_minutes` - (Optional) Number of minutes to wait before executing the timeout action. Valid range: 1-20160 minutes. Default: `1440` (24 hours). ### `linear_configuration` Block The `linear_configuration` configuration block supports the following: * `step_bake_time_in_minutes` - (Optional) Number of minutes to wait between each step during a linear deployment. Valid range: 0-1440 minutes. * `step_percent` - (Optional) Percentage of traffic to shift in each step during a linear deployment. Valid range: 3.0-100.0. ### `canary_configuration` Block The `canary_configuration` configuration block supports the following: * `canary_bake_time_in_minutes` - (Optional) Number of minutes to wait before shifting all traffic to the new deployment. Valid range: 0-1440 minutes. * `canary_percent` - (Optional) Percentage of traffic to route to the canary deployment. Valid range: 0.1-100.0. ### `deployment_circuit_breaker` Block The `deployment_circuit_breaker` configuration block supports the following: * `enable` - (Required) Whether to enable the deployment circuit breaker logic for the service. * `rollback` - (Required) Whether to enable Amazon ECS to roll back the service if a service deployment fails. If rollback is enabled, when a service deployment fails, the service is rolled back to the last deployment that completed successfully. ### `deployment_controller` Block The `deployment_controller` configuration block supports the following: * `type` - (Optional) Type of deployment controller. Valid values: `CODE_DEPLOY`, `ECS`, `EXTERNAL`. Default: `ECS`. ### `load_balancer` Block `load_balancer` supports the following: * `advanced_configuration` - (Optional) Configuration block for Blue/Green deployment settings. Required when using `BLUE_GREEN` deployment strategy. [See below](#advanced_configuration-block). * `container_name` - (Required) Name of the container to associate with the load balancer (as it appears in a container definition). * `container_port` - (Required) Port on the container to associate with the load balancer. * `elb_name` - (Optional) Name of the ELB (Classic) to associate with the service. Required for ELB Classic. * `target_group_arn` - (Optional) ARN of the Load Balancer target group to associate with the service. Required for ALB/NLB. -> **Version note:** Multiple `load_balancer` configuration block support was added in Terraform AWS Provider version 2.22.0. This allows configuration of [ECS service support for multiple target groups](https://aws.amazon.com/about-aws/whats-new/2019/07/amazon-ecs-services-now-support-multiple-load-balancer-target-groups/). ### `advanced_configuration` Block The `advanced_configuration` configuration block supports the following: * `alternate_target_group_arn` - (Required) ARN of the alternate target group to use for Blue/Green deployments. * `production_listener_rule` - (Required) ARN of the listener rule that routes production traffic. * `role_arn` - (Required) ARN of the IAM role that allows ECS to manage the target groups. * `test_listener_rule` - (Optional) ARN of the listener rule that routes test traffic. ### `network_configuration` Block For more information, see [Task Networking](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking.html). `network_configuration` support the following: * `assign_public_ip` - (Optional) Assign a public IP address to the ENI (Fargate launch type only). Valid values are `true` or `false`. Default `false`. * `security_groups` - (Optional) 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. * `subnets` - (Required) Subnets associated with the task or service. ### `ordered_placement_strategy` Block `ordered_placement_strategy` supports the following: * `field` - (Optional) For the `spread` placement strategy, valid values are `instanceId` (or `host`, which has the same effect), or any platform or custom attribute that is applied to a container instance. For the `binpack` type, valid values are `memory` and `cpu`. For the `random` type, this attribute is not needed. For more information, see [Placement Strategy](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_PlacementStrategy.html). * `type` - (Required) Type of placement strategy. Must be one of: `binpack`, `random`, or `spread` -> **Note:** for `spread`, `host` and `instanceId` will be normalized, by AWS, to be `instanceId`. This means the statefile will show `instanceId` but your config will differ if you use `host`. ### `placement_constraints` Block `placement_constraints` support the following: * `expression` - (Optional) Cluster Query Language expression to apply to the constraint. Does not need to be specified for the `distinctInstance` type. For more information, see [Cluster Query Language in the Amazon EC2 Container Service Developer Guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html). * `type` - (Required) Type of constraint. The only valid values at this time are `memberOf` and `distinctInstance`. ### `service_registries` Block `service_registries` support the following: * `container_name` - (Optional) Container name value, already specified in the task definition, to be used for your service discovery service. * `container_port` - (Optional) Port value, already specified in the task definition, to be used for your service discovery service. * `port` - (Optional) Port value used if your Service Discovery service specified an SRV record. * `registry_arn` - (Required) ARN of the Service Registry. The currently supported service registry is Amazon Route 53 Auto Naming Service(`aws_service_discovery_service`). For more information, see [Service](https://docs.aws.amazon.com/Route53/latest/APIReference/API_autonaming_Service.html) ### `service_connect_configuration` Block `service_connect_configuration` supports the following: * `access_log_configuration` - (Optional) Configuration for Service Connect access logs. [See below](#access_log_configuration-block). * `enabled` - (Required) Whether to use Service Connect with this service. * `log_configuration` - (Optional) Log configuration for the container. [See below](#log_configuration-block). * `namespace` - (Optional) Namespace name or ARN of the [`aws_service_discovery_http_namespace`](/docs/providers/aws/r/service_discovery_http_namespace.html) for use with Service Connect. * `service` - (Optional) List of Service Connect service objects. [See below](#service-block). ### `access_log_configuration` Block `access_log_configuration` supports the following: * `format` - (Required) Format for Service Connect access log output. Valid values: `TEXT`, `JSON`. See [AWS documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect-envoy-access-logs.html) for format details. * `include_query_parameters` - (Optional) Whether to include query parameters in Service Connect access logs. Valid values: `ENABLED`, `DISABLED`. Default: `DISABLED`. Query parameters may contain sensitive information. ~> **NOTE:** Access logs are delivered to the destination log group specified in the `log_configuration` block. You must configure `log_configuration` to enable access logs. ~> **SECURITY WARNING:** When `include_query_parameters` is set to `ENABLED`, query parameters (which may contain sensitive data such as request IDs, tokens, or session identifiers) will be included in access logs. ### `log_configuration` Block `log_configuration` supports the following: * `log_driver` - (Required) Log driver to use for the container. * `options` - (Optional) Configuration options to send to the log driver. * `secret_option` - (Optional) Secrets to pass to the log configuration. [See below](#secret_option-block). ### `secret_option` Block `secret_option` supports the following: * `name` - (Required) Name of the secret. * `value_from` - (Required) Secret to expose to the container. The supported values are either the full ARN of the AWS Secrets Manager secret or the full ARN of the parameter in the SSM Parameter Store. ### `service` Block `service` supports the following: * `client_alias` - (Optional) List of client aliases for this Service Connect service. You use these to assign names that can be used by client applications. For each service block where enabled is true, exactly one `client_alias` with one `port` should be specified. [See below](#client_alias-block). * `discovery_name` - (Optional) Name of the new AWS Cloud Map service that Amazon ECS creates for this Amazon ECS service. * `ingress_port_override` - (Optional) Port number for the Service Connect proxy to listen on. * `port_name` - (Required) Name of one of the `portMappings` from all the containers in the task definition of this Amazon ECS service. * `timeout` - (Optional) Configuration timeouts for Service Connect * `tls` - (Optional) Configuration for enabling TLS ### `timeout` Block `timeout` supports the following: * `idle_timeout_seconds` - (Optional) Amount of time in seconds a connection will stay active while idle. A value of 0 can be set to disable idleTimeout. * `per_request_timeout_seconds` - (Optional) Amount of time in seconds for the upstream to respond with a complete response per request. A value of 0 can be set to disable perRequestTimeout. Can only be set when appProtocol isn't TCP. ### `tls` Block `tls` supports the following: * `issuer_cert_authority` - (Required) Details of the certificate authority which will issue the certificate. * `kms_key` - (Optional) KMS key used to encrypt the private key in Secrets Manager. * `role_arn` - (Optional) ARN of the IAM Role that's associated with the Service Connect TLS. ### `issuer_cert_authority` Block `issuer_cert_authority` supports the following: * `aws_pca_authority_arn` - (Required) ARN of the [`aws_acmpca_certificate_authority`](/docs/providers/aws/r/acmpca_certificate_authority.html) used to create the TLS Certificates. ### `client_alias` Block `client_alias` supports the following: * `dns_name` - (Optional) Name that you use in the applications of client tasks to connect to this service. * `port` - (Required) Listening port number for the Service Connect proxy. This port is available inside of all of the tasks within the same namespace. * `test_traffic_rules` - (Optional) Configuration block for test traffic routing rules. [See below](#test_traffic_rules-block). ### `test_traffic_rules` Block The `test_traffic_rules` configuration block supports the following: * `header` - (Optional) Configuration block for header-based routing rules. [See below](#header-block). ### `header` Block The `header` configuration block supports the following: * `name` - (Required) Name of the HTTP header to match. * `value` - (Required) Configuration block for header value matching criteria. [See below](#value-block). ### `value` Block The `value` configuration block supports the following: * `exact` - (Required) Exact string value to match in the header. ### `tag_specifications` Block `tag_specifications` supports the following: * `propagate_tags` - (Optional) Whether to propagate the tags from the task definition to the Amazon EBS volume. * `resource_type` - (Required) Type of volume resource. Valid values, `volume`. * `tags` - (Optional) Tags applied to this Amazon EBS volume. `AmazonECSCreated` and `AmazonECSManaged` are reserved tags that can't be used. ## Attribute Reference This resource exports the following attributes in addition to the arguments above: * `arn` - ARN that identifies the service. * `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). ## Timeouts [Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): - `create` - (Default `20m`) - `update` - (Default `20m`) - `delete` - (Default `20m`) ## 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_service.example identity = { cluster = "example-cluster" name = "example-service" } } resource "aws_ecs_service" "example" { ### Configuration omitted for brevity ### } ``` ### Identity Schema #### Required * `cluster` (String) The name of the cluster. * `name` (String) The name of the service. #### 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 services using the `name` together with ECS cluster `name`. For example: ```terraform import { to = aws_ecs_service.imported id = "cluster-name/service-name" } ``` Using `terraform import`, import ECS services using the `name` together with ECS cluster `name`. For example: ```console % terraform import aws_ecs_service.imported cluster-name/service-name ```