Skip to main content
This example demonstrates a comprehensive ECS deployment using the root module. It creates a Fargate cluster with an EC2 Auto Scaling Group capacity provider, deploys a service with FireLens logging, Service Connect, and an Application Load Balancer.

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

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 = true and the app container sets enable_cloudwatch_logging = false with logDriver = "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 ReadOnlyAccess policy and a custom s3:List* statement.

Fargate Example

Simpler Fargate-only deployment with blue/green.

EC2 Autoscaling Example

Standalone cluster + service modules with EC2 ASG.