This module provides a primitive Terraform module for creating an Amazon ECS service with support for various configurations including load balancers, service discovery, and more.
- Supports Fargate and EC2 launch types
- Configurable network settings with subnets and security groups
- Load balancer integration
- Service Connect for service-to-service communication
- Service discovery registries
- Capacity provider strategies
- Deployment configurations with circuit breakers and alarms
- Volume configurations for EBS attachments
- ECS Exec support
- Comprehensive tagging and managed tags
module "ecs_service" {
source = "path/to/module"
name = "my-ecs-service"
cluster = aws_ecs_cluster.example.arn
task_definition = aws_ecs_task_definition.example.arn
desired_count = 2
launch_type = "FARGATE"
network_configuration = {
subnets = [aws_subnet.example.id]
security_groups = [aws_security_group.example.id]
assign_public_ip = false
}
tags = {
Environment = "dev"
}
}- 1 ECS Service
- 1 Service Discovery Service (data source, if Service Connect lookup is configured)
| Name | Version |
|---|---|
| terraform | >= 1.0 |
| aws | ~> 5.0 |
No modules.
| Name | Type |
|---|---|
| aws_ecs_service.this | resource |
| aws_service_discovery_service.service_connect | data source |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| name | Name for the ECS service | string |
n/a | yes |
| tags | A map of tags to add to the ECS service | map(string) |
{} |
no |
| cluster | ARN of the ECS cluster where this service will be placed | string |
n/a | yes |
| task_definition | The family and revision (family:revision) or full ARN of the task definition to run in your service | string |
n/a | yes |
| desired_count | The number of instances of the task definition to place and keep running | number |
1 |
no |
| launch_type | The launch type on which to run your service. Valid values: EC2, FARGATE, EXTERNAL | string |
"FARGATE" |
no |
| platform_version | The platform version on which to run your service. Only applicable for launch_type set to FARGATE | string |
"LATEST" |
no |
| iam_role | The ARN of an IAM role that allows your Amazon ECS service to make calls to other AWS services | string |
null |
no |
| enable_execute_command | Whether to enable Amazon ECS Exec for the tasks in the service | bool |
false |
no |
| enable_ecs_managed_tags | Whether to enable Amazon ECS managed tags for the tasks in the service | bool |
false |
no |
| propagate_tags | Whether to propagate the tags from the task definition or the service to the tasks | string |
"SERVICE" |
no |
| health_check_grace_period_seconds | Health check grace period in seconds for the service when using load balancers | number |
null |
no |
| wait_for_steady_state | Whether to wait for the service to reach a steady state before continuing | bool |
false |
no |
| force_new_deployment | Whether to force a new task deployment of the service | bool |
false |
no |
| network_configuration | Network configuration for the ECS service | object({ |
null |
no |
| load_balancer | Load balancer configuration for the service | list(object({ |
[] |
no |
| service_connect_configuration | Service Connect configuration for the service | object({ |
null |
no |
| service_registries | Service discovery registries for the service | list(object({ |
[] |
no |
| service_connect_registry_arn | ARN of the Service Connect service to register in service registries for external discovery | string |
null |
no |
| service_connect_registry_port | Port value for the Service Connect service registry entry | number |
null |
no |
| service_connect_registry_container_name | Container name for the Service Connect service registry entry | string |
null |
no |
| service_connect_registry_container_port | Container port for the Service Connect service registry entry | number |
null |
no |
| service_connect_discovery_name | Discovery name of the Service Connect service to lookup (should match service.discovery_name in service_connect_configuration) | string |
null |
no |
| service_connect_namespace_id | Namespace ID for Service Connect service discovery lookup | string |
null |
no |
| capacity_provider_strategy | Capacity provider strategy to use for the service | list(object({ |
[] |
no |
| deployment_configuration | Deployment configuration for the service | object({ |
{ |
no |
| placement_constraints | Placement constraints for the service | list(object({ |
[] |
no |
| ordered_placement_strategy | Placement strategy for the service | list(object({ |
[] |
no |
| volume_configuration | Configuration for EBS volumes that are attached to tasks | object({ |
null |
no |
| Name | Description |
|---|---|
| id | The ID of the ECS service |
| name | The name of the ECS service |
| cluster | The cluster the ECS service is associated with |
| desired_count | The desired number of tasks for the ECS service |
| task_definition | The task definition ARN used by the ECS service |
| launch_type | The launch type of the ECS service |
| platform_version | The platform version of the ECS service |
| deployment_configuration | The deployment configuration of the ECS service |
| network_configuration | The network configuration of the ECS service |
| load_balancer_configuration | The load balancer configuration of the ECS service |
| service_connect_configuration | The service connect configuration of the ECS service |
| service_registries | The effective service registries configuration of the ECS service (includes Service Connect registry if configured) |
| service_connect_service_arn | ARN of the Service Connect service discovered via data source (if lookup is configured) |
| service_connect_service_discovery_name | Discovery name of the Service Connect service (from configuration) |
| capacity_provider_strategy | The capacity provider strategy of the ECS service |
| placement_constraints | The placement constraints of the ECS service |
| placement_strategy | The placement strategy of the ECS service |
| volume_configuration | The volume configuration of the ECS service |
| enable_execute_command | Whether ECS Exec is enabled for the service |
| enable_ecs_managed_tags | Whether ECS managed tags are enabled for the service |
| propagate_tags | How tags are propagated to tasks |
| tags | A map of tags assigned to the ECS service |
| tags_all | A map of tags assigned to the resource, including provider default_tags |
| service_details | Comprehensive details about the ECS service for integration purposes |
| service_configuration | Summary of the ECS service configuration |