-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecs.tf
75 lines (66 loc) · 1.83 KB
/
ecs.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
resource "aws_ecs_cluster" "my_cluster" {
name = local.project_name
}
resource "aws_ecs_task_definition" "backend_task" {
family = local.backend_app
container_definitions = <<DEFINITION
[
{
"name": "${local.backend_app}",
"image": "${var.backend_app_image}",
"essential": true,
"portMappings": [
{
"containerPort": 3000,
"hostPort": 3000
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/toomio-backend",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs",
"awslogs-create-group": "true"
}
},
"memory": 512,
"cpu": 256
}
]
DEFINITION
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
memory = 512
cpu = 256
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
depends_on = [
aws_cloudwatch_log_group.backend_log_group
]
}
resource "aws_cloudwatch_log_group" "backend_log_group" {
name = "/ecs/toomio-backend"
retention_in_days = 14
}
resource "aws_ecs_service" "backend_service" {
name = local.backend_app
cluster = aws_ecs_cluster.my_cluster.id
task_definition = aws_ecs_task_definition.backend_task.arn
launch_type = "FARGATE"
desired_count = 1
load_balancer {
target_group_arn = aws_lb_target_group.toomio_backend_target_group.arn
container_name = aws_ecs_task_definition.backend_task.family
container_port = 3000
}
network_configuration {
subnets = module.vpc.public_subnets
assign_public_ip = true
security_groups = [aws_security_group.service_security_group.id]
}
lifecycle {
ignore_changes = [
task_definition
]
}
}