Terraform module which creates ECS (Elastic Container Service) resources on AWS.
- ECS cluster
- Fargate capacity providers
- EC2 AutoScaling Group capacity providers
module "ecs" {
source = "terraform-aws-modules/ecs/aws"
cluster_name = "ecs-fargate"
cluster_configuration = {
execute_command_configuration = {
logging = "OVERRIDE"
log_configuration = {
cloud_watch_log_group_name = "/aws/ecs/aws-ec2"
}
}
}
fargate_capacity_providers = {
FARGATE = {
default_capacity_provider_strategy = {
weight = 50
}
}
FARGATE_SPOT = {
default_capacity_provider_strategy = {
weight = 50
}
}
}
tags = {
Environment = "Development"
Project = "EcsEc2"
}
}
module "ecs" {
source = "terraform-aws-modules/ecs/aws"
cluster_name = "ecs-ec2"
cluster_configuration = {
execute_command_configuration = {
logging = "OVERRIDE"
log_configuration = {
cloud_watch_log_group_name = "/aws/ecs/aws-ec2"
}
}
}
autoscaling_capacity_providers = {
one = {
auto_scaling_group_arn = "arn:aws:autoscaling:eu-west-1:012345678901:autoScalingGroup:08419a61:autoScalingGroupName/ecs-ec2-one-20220603194933774300000011"
managed_termination_protection = "ENABLED"
managed_scaling = {
maximum_scaling_step_size = 5
minimum_scaling_step_size = 1
status = "ENABLED"
target_capacity = 60
}
default_capacity_provider_strategy = {
weight = 60
base = 20
}
}
two = {
auto_scaling_group_arn = "arn:aws:autoscaling:eu-west-1:012345678901:autoScalingGroup:08419a61:autoScalingGroupName/ecs-ec2-two-20220603194933774300000022"
managed_termination_protection = "ENABLED"
managed_scaling = {
maximum_scaling_step_size = 15
minimum_scaling_step_size = 5
status = "ENABLED"
target_capacity = 90
}
default_capacity_provider_strategy = {
weight = 40
}
}
}
tags = {
Environment = "Development"
Project = "EcsEc2"
}
}
module "ecs" {
source = "terraform-aws-modules/ecs/aws"
cluster_name = "ecs-mixed"
cluster_configuration = {
execute_command_configuration = {
logging = "OVERRIDE"
log_configuration = {
cloud_watch_log_group_name = "/aws/ecs/aws-ec2"
}
}
}
fargate_capacity_providers = {
FARGATE = {
default_capacity_provider_strategy = {
weight = 50
}
}
FARGATE_SPOT = {
default_capacity_provider_strategy = {
weight = 50
}
}
}
autoscaling_capacity_providers = {
one = {
auto_scaling_group_arn = "arn:aws:autoscaling:eu-west-1:012345678901:autoScalingGroup:08419a61:autoScalingGroupName/ecs-ec2-one-20220603194933774300000011"
managed_termination_protection = "ENABLED"
managed_scaling = {
maximum_scaling_step_size = 5
minimum_scaling_step_size = 1
status = "ENABLED"
target_capacity = 60
}
default_capacity_provider_strategy = {
weight = 60
base = 20
}
}
two = {
auto_scaling_group_arn = "arn:aws:autoscaling:eu-west-1:012345678901:autoScalingGroup:08419a61:autoScalingGroupName/ecs-ec2-two-20220603194933774300000022"
managed_termination_protection = "ENABLED"
managed_scaling = {
maximum_scaling_step_size = 15
minimum_scaling_step_size = 5
status = "ENABLED"
target_capacity = 90
}
default_capacity_provider_strategy = {
weight = 40
}
}
}
tags = {
Environment = "Development"
Project = "EcsEc2"
}
}
The following values are provided to toggle on/off creation of the associated resources as desired:
module "ecs" {
source = "terraform-aws-modules/ecs/aws"
# Disable creation of cluster and all resources
create = false
# ... omitted
}
Name | Version |
---|---|
terraform | >= 1.0 |
aws | >= 4.6 |
Name | Version |
---|---|
aws | >= 4.6 |
No modules.
Name | Type |
---|---|
aws_ecs_capacity_provider.this | resource |
aws_ecs_cluster.this | resource |
aws_ecs_cluster_capacity_providers.this | resource |
Name | Description | Type | Default | Required |
---|---|---|---|---|
autoscaling_capacity_providers | Map of autoscaling capacity provider definitons to create for the cluster | any |
{} |
no |
cluster_configuration | The execute command configuration for the cluster | any |
{} |
no |
cluster_name | Name of the cluster (up to 255 letters, numbers, hyphens, and underscores) | string |
"" |
no |
cluster_settings | Configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster | map(string) |
{ |
no |
create | Determines whether resources will be created (affects all resources) | bool |
true |
no |
default_capacity_provider_use_fargate | Determines whether to use Fargate or autoscaling for default capacity provider strategy | bool |
true |
no |
fargate_capacity_providers | Map of Fargate capacity provider definitions to use for the cluster | any |
{} |
no |
tags | A map of tags to add to all resources | map(string) |
{} |
no |
Name | Description |
---|---|
autoscaling_capacity_providers | Map of autoscaling capacity providers created and their attributes |
cluster_arn | ARN that identifies the cluster |
cluster_capacity_providers | Map of cluster capacity providers attributes |
cluster_id | ID that identifies the cluster |
cluster_name | Name that identifies the cluster |
Module is maintained by Anton Babenko with help from these awesome contributors.
Apache 2 Licensed. See LICENSE for full details.