This module creates an ECS cluster supporting EC2 instances, Fargate, and Fargate Spot capacity providers.
Only cluster_name is required.
The cluster registers FARGATE, FARGATE_SPOT, and EC2 capacity providers. To use Fargate exclusively, set EC2 instances to 0:
ecs_cluster_instances_desired = 0
ecs_cluster_instances_autoscale_max = 0Services can then use Fargate by setting ecs_service_fargate = true. See MIGRATION_EC2_TO_FARGATE.md for migration steps.
The cluster registers FARGATE, FARGATE_SPOT, and conditionally registers an EC2 autoscale capacity provider. The instances_autoscale_max > 0 && instances_desired == 0 condition is required because:
- The EC2 autoscale capacity provider is only created when autoscaling is enabled (
instances_autoscale_max > 0) and there are no fixed instances (instances_desired == 0) - The capacity provider depends on the Autoscaling Group (ASG), which is also conditionally created
- Referencing
aws_ecs_capacity_provider.autoscale[0].namewhencount = 0would cause a Terraform error - The conditional ensures we only reference the resource when it exists
Services explicitly set their capacity provider strategy, so the cluster default strategy only applies to services using use_default_capacity_provider = true.