-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.tf
48 lines (41 loc) · 1.54 KB
/
main.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
locals {
"service_count" = "${length(var.pga_api_key) > 0 ? 1 : 0}"
}
data "aws_ecs_cluster" "ecs" {
cluster_name = "${var.ecs_cluster}"
}
data "aws_region" "current" {
current = true
}
data "template_file" "pganalyze" {
template = "${file("${path.module}/files/pganalyze.json")}"
vars {
task_identifier = "${var.task_identifier}"
db_url = "postgres://${var.db_username}:${var.db_password}@${var.rds_endpoint}/${var.db_name}"
image = "${var.docker_image}"
pga_api_key = "${var.pga_api_key}"
aws_instance_id = "${var.aws_instance_id}" # we can almost certainly derive this
aws_region = "${data.aws_region.current.name}"
awslogs_group = "${var.log_group}"
awslogs_region = "${data.aws_region.current.name}"
awslogs_stream_prefix = "tf"
}
}
resource "aws_ecs_task_definition" "pganalyze" {
count = "${local.service_count}"
family = "pganalyze-${var.env}-${var.task_identifier}"
container_definitions = "${data.template_file.pganalyze.rendered}"
network_mode = "bridge"
task_role_arn = "${aws_iam_role.pganalyze_task.arn}"
}
resource "aws_ecs_service" "pganalyze" {
count = "${local.service_count}"
name = "pganalyze-${var.env}-${var.task_identifier}"
cluster = "${data.aws_ecs_cluster.ecs.id}"
task_definition = "${aws_ecs_task_definition.pganalyze.arn}"
desired_count = 1
placement_strategy {
type = "binpack"
field = "memory"
}
}