|
|
@ -1,20 +1,16 @@ |
|
|
|
locals { |
|
|
|
|
|
|
|
api_name = "${var.project}-api" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resource "aws_ecs_cluster" "my_cluster" { |
|
|
|
resource "aws_ecs_cluster" "my_cluster" { |
|
|
|
name = "my_cluster" |
|
|
|
name = "${var.project}_cluster" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
resource "aws_ecs_service" "api_ecs" { |
|
|
|
resource "aws_ecs_service" "api_ecs" { |
|
|
|
name = local.api_name |
|
|
|
name = var.api_name |
|
|
|
task_definition = aws_ecs_task_definition.api_task.arn |
|
|
|
task_definition = aws_ecs_task_definition.api_task.arn |
|
|
|
cluster = aws_ecs_cluster.my_cluster.id |
|
|
|
cluster = aws_ecs_cluster.my_cluster.id |
|
|
|
launch_type = "FARGATE" |
|
|
|
launch_type = "FARGATE" |
|
|
|
load_balancer { |
|
|
|
load_balancer { |
|
|
|
target_group_arn = aws_lb_target_group.api_lb_target.arn |
|
|
|
target_group_arn = aws_lb_target_group.api_lb_target.arn |
|
|
|
container_name = local.api_name |
|
|
|
container_name = var.api_name |
|
|
|
container_port = "3000" |
|
|
|
container_port = "${var.service_port}" |
|
|
|
} |
|
|
|
} |
|
|
|
desired_count = 1 |
|
|
|
desired_count = 1 |
|
|
|
network_configuration { |
|
|
|
network_configuration { |
|
|
@ -28,7 +24,7 @@ resource "aws_ecs_service" "api_ecs" { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
resource "aws_ecs_task_definition" "api_task" { |
|
|
|
resource "aws_ecs_task_definition" "api_task" { |
|
|
|
family = local.api_name |
|
|
|
family = var.api_name |
|
|
|
execution_role_arn = aws_iam_role.api_exec_role.arn |
|
|
|
execution_role_arn = aws_iam_role.api_exec_role.arn |
|
|
|
cpu = 256 |
|
|
|
cpu = 256 |
|
|
|
memory = 512 |
|
|
|
memory = 512 |
|
|
@ -36,18 +32,18 @@ resource "aws_ecs_task_definition" "api_task" { |
|
|
|
network_mode = "awsvpc" |
|
|
|
network_mode = "awsvpc" |
|
|
|
|
|
|
|
|
|
|
|
container_definitions = jsonencode([{ |
|
|
|
container_definitions = jsonencode([{ |
|
|
|
name: "${local.api_name}", |
|
|
|
name : "${var.api_name}", |
|
|
|
image : "${var.container_image}", |
|
|
|
image : "${var.container_image}", |
|
|
|
portMappings : [ |
|
|
|
portMappings : [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
containerPort : 3000 |
|
|
|
containerPort : var.service_port |
|
|
|
} |
|
|
|
} |
|
|
|
], |
|
|
|
], |
|
|
|
logConfiguration : { |
|
|
|
logConfiguration : { |
|
|
|
logDriver : "awslogs", |
|
|
|
logDriver : "awslogs", |
|
|
|
options : { |
|
|
|
options : { |
|
|
|
awslogs-region : "${var.region}", |
|
|
|
awslogs-region : "${var.region}", |
|
|
|
awslogs-group : "/ecs/${local.api_name}", |
|
|
|
awslogs-group : "/ecs/${var.api_name}", |
|
|
|
awslogs-stream-prefix : "ecs" |
|
|
|
awslogs-stream-prefix : "ecs" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -55,5 +51,5 @@ resource "aws_ecs_task_definition" "api_task" { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
resource "aws_cloudwatch_log_group" "log_group" { |
|
|
|
resource "aws_cloudwatch_log_group" "log_group" { |
|
|
|
name = "/ecs/${local.api_name}" |
|
|
|
name = "/ecs/${var.api_name}" |
|
|
|
} |
|
|
|
} |
|
|
|