|
|
|
@ -1,20 +1,16 @@
|
|
|
|
|
locals { |
|
|
|
|
api_name = "${var.project}-api" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
resource "aws_ecs_cluster" "my_cluster" { |
|
|
|
|
name = "my_cluster" |
|
|
|
|
name = "${var.project}_cluster" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
resource "aws_ecs_service" "api_ecs" { |
|
|
|
|
name = local.api_name |
|
|
|
|
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 = local.api_name |
|
|
|
|
container_port = "3000" |
|
|
|
|
container_name = var.api_name |
|
|
|
|
container_port = "${var.service_port}" |
|
|
|
|
} |
|
|
|
|
desired_count = 1 |
|
|
|
|
network_configuration { |
|
|
|
@ -28,7 +24,7 @@ resource "aws_ecs_service" "api_ecs" {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
cpu = 256 |
|
|
|
|
memory = 512 |
|
|
|
@ -36,18 +32,18 @@ resource "aws_ecs_task_definition" "api_task" {
|
|
|
|
|
network_mode = "awsvpc" |
|
|
|
|
|
|
|
|
|
container_definitions = jsonencode([{ |
|
|
|
|
name: "${local.api_name}", |
|
|
|
|
name : "${var.api_name}", |
|
|
|
|
image : "${var.container_image}", |
|
|
|
|
portMappings : [ |
|
|
|
|
{ |
|
|
|
|
containerPort : 3000 |
|
|
|
|
containerPort : var.service_port |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
logConfiguration : { |
|
|
|
|
logDriver : "awslogs", |
|
|
|
|
options : { |
|
|
|
|
awslogs-region : "${var.region}", |
|
|
|
|
awslogs-group : "/ecs/${local.api_name}", |
|
|
|
|
awslogs-group : "/ecs/${var.api_name}", |
|
|
|
|
awslogs-stream-prefix : "ecs" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -55,5 +51,5 @@ resource "aws_ecs_task_definition" "api_task" {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
resource "aws_cloudwatch_log_group" "log_group" { |
|
|
|
|
name = "/ecs/${local.api_name}" |
|
|
|
|
name = "/ecs/${var.api_name}" |
|
|
|
|
} |
|
|
|
|