resource "aws_ecs_task_definition" "app" {
family = "${local.full_app_name}-app-task"
execution_role_arn = var.ecs_task_execution_role
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = var.container_fargate_cpu
memory = var.container_fargate_memory
}
data "aws_ecs_task_definition" "app" {
task_definition = aws_ecs_task_definition.app.family
depends_on = [aws_ecs_task_definition.app]
}
resource "aws_ecs_service" "main" {
name = "${local.full_app_name}-service"
cluster = "${var.environment}-csp-cluster"
task_definition = aws_ecs_task_definition.app.family
desired_count = var.app_count
launch_type = "FARGATE"
network_configuration {
security_groups = [aws_security_group.ecs_tasks.id]
subnets = var.private_subnet_ids
}
load_balancer {
target_group_arn = aws_alb_target_group.target_group.arn
container_name = "${local.full_app_name}-app"
container_port = var.app_port
}
}