A Terraform module for creating ECS infrastructure in AWS. The module allows modular creation of:
- ECS Cluster
- Task Definition
- ECS Service
- Support for Fargate and EC2
- Container Insights support
- EFS support
- Service Discovery support
- Capacity Providers support
- Deployment Circuit Breaker support
- ECS Exec support
- Load Balancer support
- Network Configuration support
- Tagging support
- Terraform >= 0.13
- AWS Provider >= 3.0
module "ecs" {
source = "Senora-dev/ecs/aws"
# Cluster Configuration
create_cluster = true
cluster_name = "my-cluster"
container_insights_enabled = true
# Task Definition Configuration
create_task_definition = true
task_family = "my-task"
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
task_cpu = 256
task_memory = 512
container_definitions = [
{
name = "my-container"
image = "nginx:latest"
essential = true
portMappings = [
{
containerPort = 80
hostPort = 80
protocol = "tcp"
}
]
}
]
# Service Configuration
create_service = true
service_name = "my-service"
desired_count = 2
launch_type = "FARGATE"
platform_version = "LATEST"
network_configuration = {
subnets = ["subnet-12345678", "subnet-87654321"]
security_groups = ["sg-12345678"]
assign_public_ip = false
}
deployment_circuit_breaker = {
enable = true
rollback = true
}
tags = {
Environment = "production"
}
}
Name | Description | Type | Default | Required |
---|---|---|---|---|
create_cluster | Whether to create an ECS cluster | bool |
true |
no |
cluster_name | Name of the cluster | string |
n/a | yes |
container_insights_enabled | Whether to enable Container Insights | bool |
false |
no |
execute_command_logging | ECS Exec logging settings | string |
"NONE" |
no |
create_task_definition | Whether to create a task definition | bool |
true |
no |
task_family | Name of the task definition family | string |
n/a | yes |
requires_compatibilities | Supported launch types | list(string) |
["EC2"] |
no |
network_mode | Network mode for the containers | string |
"bridge" |
no |
task_cpu | Number of CPU units for the task | number |
256 |
no |
task_memory | Amount of memory (in MiB) for the task | number |
512 |
no |
execution_role_arn | ARN of the execution role | string |
null |
no |
task_role_arn | ARN of the task role | string |
null |
no |
container_definitions | Container definitions | list(any) |
n/a | yes |
volumes | Volume definitions | list(object) |
[] |
no |
create_service | Whether to create an ECS service | bool |
true |
no |
service_name | Name of the service | string |
n/a | yes |
cluster_id | ID of the cluster (required if create_cluster is false) | string |
null |
no |
task_definition_arn | ARN of the task definition (required if create_task_definition is false) | string |
null |
no |
desired_count | Desired number of tasks | number |
1 |
no |
deployment_minimum_healthy_percent | Minimum healthy percent during deployment | number |
100 |
no |
deployment_maximum_percent | Maximum percent during deployment | number |
200 |
no |
launch_type | Launch type | string |
"EC2" |
no |
scheduling_strategy | Scheduling strategy | string |
"REPLICA" |
no |
platform_version | Platform version | string |
"LATEST" |
no |
enable_execute_command | Whether to enable ECS Exec | bool |
false |
no |
network_configuration | Network configuration | object |
null |
no |
load_balancer | Load Balancer configuration | object |
null |
no |
service_registries | Service Discovery registries | list(object) |
[] |
no |
capacity_provider_strategy | Capacity Provider strategy | list(object) |
[] |
no |
deployment_circuit_breaker | Deployment Circuit Breaker configuration | object |
null |
no |
tags | Tags for all resources | map(string) |
{} |
no |
Name | Description |
---|---|
cluster_id | ID of the cluster |
cluster_arn | ARN of the cluster |
cluster_name | Name of the cluster |
task_definition_arn | ARN of the task definition |
task_definition_revision | Revision of the task definition |
service_id | ID of the service |
service_name | Name of the service |
service_cluster | Cluster where the service is running |
service_desired_count | Desired number of tasks |
- Complete Example - Shows full usage of the module with VPC, security group, cluster, task definition, and service.
MIT Licensed. See LICENSE for full details.
This module is maintained by Senora.dev.