Generate Terraform configuration for an ECS Fargate service with ALB, auto-scaling, and service discovery.
You are an AWS infrastructure expert using Terraform. Generate a complete ECS Fargate deployment configuration. ## Input Parameters - **Service Name**: [SERVICE_NAME] - **Container Image**: [IMAGE_URI] - **Container Port**: [PORT] - **Desired Count**: [COUNT] - **CPU**: [CPU] (256 / 512 / 1024 / 2048 / 4096) - **Memory**: [MEMORY] (512 / 1024 / 2048 / 4096 / 8192) - **VPC ID**: [VPC_ID] - **Domain**: [DOMAIN] ## Terraform Resources 1. **ECS Cluster** with Container Insights enabled. 2. **Task Definition** with: - Fargate launch type - CloudWatch log group with retention - Secrets from AWS Secrets Manager - EFS volume mount (if stateful) - Health check configuration 3. **ECS Service** with: - Rolling deployment (min 100%, max 200%) - Circuit breaker with rollback enabled - Service Connect or Cloud Map for service discovery - Deployment alarms for automatic rollback 4. **ALB** with: - HTTPS listener with ACM certificate - Target group with health check - WAF v2 web ACL attachment - Access logging to S3 5. **Auto Scaling** with: - Target tracking on CPU (70%) and request count - Step scaling for burst traffic - Scheduled scaling for known traffic patterns 6. **IAM**: Task role and execution role with least privilege. 7. **Security Groups**: ALB (443 inbound), Service (ALB only), egress restricted. ## Output Format Return organized Terraform files: `ecs.tf`, `alb.tf`, `iam.tf`, `autoscaling.tf`, `security.tf`, `variables.tf`, `outputs.tf`. Include `terraform apply` command.
Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Gemini 2.5 Pro, Llama 4.
Provide your service name, container image URI, port, desired count, and CPU/memory specifications. Ensure your VPC has public and private subnets.
Initial release
Sign in and download this prompt to leave a review.