Skip to content

Commit

Permalink
upgrade to tf 12
Browse files Browse the repository at this point in the history
  • Loading branch information
Falpangaea committed Mar 12, 2020
1 parent 6874d2f commit f104ff7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
1 change: 1 addition & 0 deletions .terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.12.20
18 changes: 10 additions & 8 deletions iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ data "aws_iam_policy_document" "assume_role_pganalyze_task" {
}

resource "aws_iam_role" "pganalyze_task" {
count = "${local.service_count}"
count = local.service_count
name = "tf-pganalyze-${var.task_identifier}-ecsTaskRole"
path = "/"
assume_role_policy = "${data.aws_iam_policy_document.assume_role_pganalyze_task.json}"
assume_role_policy = data.aws_iam_policy_document.assume_role_pganalyze_task.json
}

resource "aws_iam_role_policy" "pganalyze_ecs_task" {
count = "${local.service_count}"
count = local.service_count
name = "tf-pganalyze-${var.task_identifier}-ecsTaskPolicy"
role = "${aws_iam_role.pganalyze_task.id}"
policy = "${data.aws_iam_policy_document.pganalyze_task_policy.json}"
role = aws_iam_role.pganalyze_task[0].id
policy = data.aws_iam_policy_document.pganalyze_task_policy.json
}

# ecsServiceRole for pganalyze

resource "aws_iam_role" "ecsServiceRole" {
count = "${local.service_count}"
count = local.service_count
name = "tf-pganalyze-${var.task_identifier}-ecsSvcRole"

assume_role_policy = <<EOF
Expand All @@ -82,10 +82,12 @@ resource "aws_iam_role" "ecsServiceRole" {
]
}
EOF

}

resource "aws_iam_role_policy_attachment" "attach-ecsServiceRole" {
count = "${local.service_count}"
role = "${aws_iam_role.ecsServiceRole.name}"
count = local.service_count
role = aws_iam_role.ecsServiceRole[0].name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole"
}

35 changes: 18 additions & 17 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
locals {
"service_count" = "${length(var.pga_api_key) > 0 ? 1 : 0}"
service_count = length(var.pga_api_key) > 0 ? 1 : 0
}

data "aws_ecs_cluster" "ecs" {
cluster_name = "${var.ecs_cluster}"
cluster_name = var.ecs_cluster
}

data "aws_region" "current" {
current = true
}

data "template_file" "pganalyze" {
template = "${file("${path.module}/files/pganalyze.json")}"
template = file("${path.module}/files/pganalyze.json")

vars {
task_identifier = "${var.task_identifier}"
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}"
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}"
count = local.service_count
family = "pganalyze-${var.env}-${var.task_identifier}"
container_definitions = "${data.template_file.pganalyze.rendered}"
container_definitions = data.template_file.pganalyze.rendered
network_mode = "bridge"
task_role_arn = "${aws_iam_role.pganalyze_task.arn}"
task_role_arn = aws_iam_role.pganalyze_task[0].arn
}

resource "aws_ecs_service" "pganalyze" {
count = "${local.service_count}"
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}"
cluster = data.aws_ecs_cluster.ecs.id
task_definition = aws_ecs_task_definition.pganalyze[0].arn
desired_count = 1

placement_strategy {
type = "binpack"
field = "memory"
}
}

1 change: 1 addition & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ variable "rds_endpoint" {
variable "log_group" {
description = "CloudWatch Log Group that will receive collector logs (must exist already)"
}

4 changes: 4 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}

0 comments on commit f104ff7

Please sign in to comment.