-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathservice.tf
53 lines (47 loc) · 1.21 KB
/
service.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
locals {
container_definitions = <<DEFINITION
[
{
"cpu": ${var.cpu},
"image": "${var.image}",
"memory": ${var.memory},
"name": "app",
"networkMode": "awsvpc",
"pseudoTerminal": true,
"portMappings": [
{
"containerPort": ${var.port},
"hostPort": ${var.port}
}
]
}
]
DEFINITION
}
resource "aws_ecs_task_definition" "app" {
family = "app"
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = "${var.cpu}"
memory = "${var.memory}"
container_definitions = "${local.container_definitions}"
}
resource "aws_ecs_service" "main" {
name = "tf-ecs-service"
cluster = "${aws_ecs_cluster.main.id}"
task_definition = "${aws_ecs_task_definition.app.arn}"
desired_count = "${var.count}"
launch_type = "FARGATE"
network_configuration {
security_groups = ["${aws_security_group.ecs_tasks.id}"]
subnets = ["${aws_subnet.private.*.id}"]
}
load_balancer {
target_group_arn = "${aws_alb_target_group.app.id}"
container_name = "app"
container_port = "${var.port}"
}
depends_on = [
"aws_alb_listener.front_end",
]
}