cluster and service sub-modules.
What is created
- ECS cluster with an EC2 ASG capacity provider (managed scaling enabled)
- EC2 Auto Scaling Group with ECS-optimized AMI
- ECS service configured for EC2 launch type
- Application Load Balancer
- VPC with private/public subnets
- IAM roles for EC2 instances
Prerequisites
You must create an Auto Scaling Group before attaching it as a capacity provider. This example uses the
terraform-aws-autoscaling module for that purpose.Code
- Cluster
- Auto Scaling Groups
- Service
Key highlights
AmazonECSManaged = truetag: The ASG must have this tag for ECS managed scaling to work.protect_from_scale_in = true: Required whenmanaged_termination_protection = "ENABLED"— prevents AWS from terminating instances before ECS drains tasks.ignore_desired_capacity_changes = true: Prevents Terraform from resetting ASG desired capacity that ECS manages.- Multiple ASGs: The example uses two ASGs with different instance types and capacity provider weights.
EC2 Autoscaling Guide
Detailed guide for EC2 Auto Scaling capacity providers.
Managed Instances Example
Simpler fleet management without managing ASGs.

