Deploy an ECS cluster with a Fargate service in a few minutes using the integrated root module.
This guide walks you through deploying a working ECS cluster with a Fargate service using the integrated root module. The cluster will run a sample frontend container with Fargate on-demand and Fargate Spot capacity providers.
Create a main.tf with the integrated root module. This configuration creates a cluster with Fargate on-demand and Fargate Spot capacity providers, and deploys a service with two containers: a FluentBit sidecar for log forwarding and the application container.
Named ecs-integrated with Fargate and Fargate Spot capacity providers
Capacity provider strategy
50/50 weight split between FARGATE (with a base of 20) and FARGATE_SPOT
ECS service
ecsdemo-frontend service with a task definition and two container definitions
Task definition
Registers the fluent-bit and ecs-sample container definitions with their CPU/memory allocations
CloudWatch log group
Created by the module for ECS cluster execute command logging
Security group
Created for the service with the ingress/egress rules you specified
Service IAM role
Created automatically because the service uses a load balancer target group
Task execution IAM role
Grants ECS permission to pull images and write logs on behalf of your tasks
The service module always ignores changes to desired_count in Terraform to avoid conflicts with application autoscaling. To change the running task count after initial deployment, use the AWS console, CLI, or a separate null_resource with a local-exec provisioner.