Skip to content

Commit

Permalink
feat: no-op if no API key provided
Browse files Browse the repository at this point in the history
  • Loading branch information
hakamadare committed Feb 5, 2018
1 parent 3c8368b commit 6874d2f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ data "aws_iam_policy_document" "assume_role_pganalyze_task" {
}

resource "aws_iam_role" "pganalyze_task" {
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}"
}

resource "aws_iam_role_policy" "pganalyze_ecs_task" {
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}"
Expand All @@ -61,7 +63,8 @@ resource "aws_iam_role_policy" "pganalyze_ecs_task" {
# ecsServiceRole for pganalyze

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

assume_role_policy = <<EOF
{
Expand All @@ -82,6 +85,7 @@ EOF
}

resource "aws_iam_role_policy_attachment" "attach-ecsServiceRole" {
count = "${local.service_count}"
role = "${aws_iam_role.ecsServiceRole.name}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole"
}
6 changes: 6 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
locals {
"service_count" = "${length(var.pga_api_key) > 0 ? 1 : 0}"
}

data "aws_ecs_cluster" "ecs" {
cluster_name = "${var.ecs_cluster}"
}
Expand All @@ -23,13 +27,15 @@ data "template_file" "pganalyze" {
}

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}"
Expand Down

0 comments on commit 6874d2f

Please sign in to comment.