forked from terraform-community-modules/tf_aws_ecs_pganalyze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
48 lines (40 loc) · 1.46 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
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" {
}
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[0].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[0].arn
desired_count = 1
ordered_placement_strategy {
type = "binpack"
field = "memory"
}
}