-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecs.tf
47 lines (40 loc) · 1.49 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
resource "aws_ecs_cluster" "main" {
name = "terraform_ecs_cluster"
}
data "template_file" "task_definition" {
template = "${file("${path.module}/task-definition.json")}"
vars {
image_url = "${var.ecs_image_url}"
container_name = "sakuten_backend"
log_group_region = "${var.aws_region}"
log_group_name = "${aws_cloudwatch_log_group.app.name}"
secret_key = "${var.secret_key}"
container_port = "${var.container_port}"
host_port = "${var.alb_container_port}"
recaptcha_secret_key = "${var.recaptcha_secret_key}"
database_url = "postgresql://${var.db_username}:${var.db_password}@${aws_db_instance.db.endpoint}/postgres"
/* timepoints = "${var.timepoints}" */
/* start_datetime = "${var.start_datetime}" */
/* end_datetime = "${var.end_datetime}" */
}
}
resource "aws_ecs_task_definition" "backend" {
family = "tf_backend_td"
container_definitions = "${data.template_file.task_definition.rendered}"
}
resource "aws_ecs_service" "main" {
name = "tf-${var.base_name}-ecs"
cluster = "${aws_ecs_cluster.main.id}"
task_definition = "${aws_ecs_task_definition.backend.arn}"
desired_count = 1
iam_role = "${aws_iam_role.ecs_service.name}"
load_balancer {
target_group_arn = "${aws_alb_target_group.main.id}"
container_name = "sakuten_backend"
container_port = "${var.container_port}"
}
depends_on = [
"aws_iam_role_policy.ecs_service",
"aws_alb_listener.front_end",
]
}