What is created
- ECS cluster with Fargate, Fargate Spot, and EC2 ASG capacity providers
- ECS service (
ecsdemo-frontend) with:- FluentBit sidecar container for log forwarding
- Service Connect with Cloud Map namespace
- ALB integration with blue/alternate target groups
- Predictive autoscaling policy
- Tasks IAM role with ReadOnlyAccess and S3 list permissions
- Application Load Balancer with HTTP listener and forwarding rules
- EC2 Auto Scaling Group (ECS-optimized AMI, t3.large)
- VPC with private/public subnets across 3 AZs
- Cloud Map HTTP namespace for Service Connect
Prerequisites
- AWS credentials configured
- Terraform >= 1.5.7
- AWS Provider >= 6.34
Code
- main.tf
- Supporting Resources
main.tf
Key highlights
- Multiple capacity providers: Fargate, Fargate Spot, and EC2 ASG all registered to the cluster. Individual containers can override with
capacity_provider_strategy. - FireLens logging: The FluentBit sidecar runs as
essential = trueand the app container setsenable_cloudwatch_logging = falsewithlogDriver = "awsfirelens". - Linear deployment:
deployment_configuration.strategy = "LINEAR"with 20% step increments every minute. - Service Connect: Uses a Cloud Map HTTP namespace ARN for service-to-service discovery.
- Tasks IAM role: Attached with
ReadOnlyAccesspolicy and a customs3:List*statement.
Fargate Example
Simpler Fargate-only deployment with blue/green.
EC2 Autoscaling Example
Standalone cluster + service modules with EC2 ASG.

