You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.5 KiB
61 lines
1.5 KiB
locals { |
|
api_name = "${var.project}-api" |
|
} |
|
|
|
resource "aws_ecs_cluster" "my_cluster" { |
|
name = "my_cluster" |
|
} |
|
|
|
resource "aws_ecs_service" "api_ecs" { |
|
name = local.api_name |
|
task_definition = aws_ecs_task_definition.api_task.arn |
|
cluster = aws_ecs_cluster.my_cluster.id |
|
launch_type = "FARGATE" |
|
load_balancer { |
|
target_group_arn = aws_lb_target_group.api_lb_target.arn |
|
container_name = local.api_name |
|
container_port = "3000" |
|
} |
|
desired_count = 1 |
|
network_configuration { |
|
assign_public_ip = false |
|
security_groups = [ |
|
aws_security_group.egress_all.id, |
|
aws_security_group.ingress_api.id, |
|
] |
|
subnets = [for s in aws_subnet.private_subnet : s.id] |
|
} |
|
} |
|
|
|
resource "aws_ecs_task_definition" "api_task" { |
|
family = local.api_name |
|
execution_role_arn = aws_iam_role.api_exec_role.arn |
|
cpu = 256 |
|
memory = 512 |
|
requires_compatibilities = ["FARGATE"] |
|
network_mode = "awsvpc" |
|
|
|
container_definitions = jsonencode([ |
|
{ |
|
name = local.api_name, |
|
image = var.container_image, |
|
portMappings = [ |
|
{ |
|
containerPort = 3000 |
|
} |
|
], |
|
logConfiguration = { |
|
logDriver = "awslogs", |
|
options = { |
|
awslogs-region = var.region, |
|
awslogs-group = "/ecs/${local.api_name}", |
|
awslogs-stream-prefix = "ecs" |
|
} |
|
} |
|
} |
|
]) |
|
} |
|
|
|
resource "aws_cloudwatch_log_group" "log_group" { |
|
name = "/ecs/${local.api_name}" |
|
}
|
|
|