# ECS on Fargate A service on Fargate in private subnets, with logs and a deployment circuit breaker. ```hcl variable "image" { type = string } variable "execution_role_arn" { type = string } variable "task_role_arn" { type = string } variable "subnet_ids" { type = list(string) } variable "security_group_ids" { type = list(string) } resource "aws_ecs_cluster" "main" { name = "workload" setting { name = "containerInsights" value = "enabled" } } resource "aws_cloudwatch_log_group" "api" { name = "/ecs/api" retention_in_days = 90 } resource "aws_ecs_task_definition" "api" { family = "api" requires_compatibilities = ["FARGATE"] network_mode = "awsvpc" cpu = "512" memory = "1024" execution_role_arn = var.execution_role_arn task_role_arn = var.task_role_arn container_definitions = jsonencode([{ name = "api" image = var.image essential = true portMappings = [{ containerPort = 8080 }] logConfiguration = { logDriver = "awslogs" options = { awslogs-group = aws_cloudwatch_log_group.api.name awslogs-region = var.region awslogs-stream-prefix = "api" } } }]) } resource "aws_ecs_service" "api" { name = "api" cluster = aws_ecs_cluster.main.id task_definition = aws_ecs_task_definition.api.arn launch_type = "FARGATE" desired_count = 2 network_configuration { subnets = var.subnet_ids security_groups = var.security_group_ids assign_public_ip = false } deployment_circuit_breaker { enable = true rollback = true } } ```