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.

56 lines
1.5 KiB

resource "aws_ecs_cluster" "my_cluster" {
name = "${var.project}_cluster"
}
resource "aws_ecs_service" "api_ecs" {
name = var.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 = var.api_name
container_port = "${var.service_port}"
}
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 = var.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 : "${var.api_name}",
image : "${var.container_image}",
portMappings : [
{
containerPort : var.service_port
}
],
logConfiguration : {
logDriver : "awslogs",
options : {
awslogs-region : "${var.region}",
awslogs-group : "/ecs/${var.api_name}",
awslogs-stream-prefix : "ecs"
}
}
}])
}
resource "aws_cloudwatch_log_group" "log_group" {
name = "/ecs/${var.api_name}"
}