Skip to content

Commit

Permalink
PLAT-2120 terraform 0.12 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Kintaro-Oe committed Dec 5, 2019
1 parent a88e701 commit 574216f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 39 deletions.
52 changes: 25 additions & 27 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
locals {
team = "${lookup(var.release, "team", "")}"
component = "${lookup(var.release, "component", "")}"
account_id = "${element(concat(data.aws_caller_identity.current.*.account_id, list("")), 0)}"
team = lookup(var.release, "team", "")
component = lookup(var.release, "component", "")
account_id = element(
concat(data.aws_caller_identity.current.*.account_id, [""]),
0,
)

name_prefix = "${
length(var.family) <= 32 ?
var.family :
format("%.24stf%.4s", var.family, sha1(var.family))
}"
name_prefix = length(var.family) <= 32 ? var.family : format("%.24stf%.4s", var.family, sha1(var.family))
}

module "task_definition" {
source = "github.com/mergermarket/tf_ecs_task_definition"
family = "${var.family}"
container_definitions = "${var.container_definitions}"
task_role_arn = "${aws_iam_role.task_role.arn}"
execution_role_arn = "${aws_iam_role.ecs_tasks_execution_role.arn}"
volume = "${var.volume}"
family = var.family
container_definitions = var.container_definitions
task_role_arn = aws_iam_role.task_role.arn
execution_role_arn = aws_iam_role.ecs_tasks_execution_role.arn
volume = var.volume
}

resource "aws_iam_role_policy" "role_policy" {
name_prefix = "${local.name_prefix}"
role = "${aws_iam_role.task_role.id}"
policy = "${var.policy}"
name_prefix = local.name_prefix
role = aws_iam_role.task_role.id
policy = var.policy
}

resource "aws_iam_role" "task_role" {
name_prefix = "${local.name_prefix}"
name_prefix = local.name_prefix
description = "Task role for ${var.family}"

assume_role_policy = "${
var.assume_role_policy == "" ?
data.aws_iam_policy_document.instance-assume-role-policy.json :
var.assume_role_policy
}"
assume_role_policy = var.assume_role_policy == "" ? data.aws_iam_policy_document.instance-assume-role-policy.json : var.assume_role_policy
}

data "aws_iam_policy_document" "instance-assume-role-policy" {
Expand All @@ -48,19 +43,20 @@ data "aws_iam_policy_document" "instance-assume-role-policy" {
}

resource "aws_iam_role" "ecs_tasks_execution_role" {
name_prefix = "${local.name_prefix}"
name_prefix = local.name_prefix
description = "Task execution role for ${var.family}"
assume_role_policy = "${data.aws_iam_policy_document.instance-assume-role-policy.json}"
assume_role_policy = data.aws_iam_policy_document.instance-assume-role-policy.json
}

data "aws_caller_identity" "current" {
count = "${var.is_test ? 0 : 1}"
count = var.is_test ? 0 : 1
}

data "aws_region" "current" {}
data "aws_region" "current" {
}

resource "aws_iam_role_policy" "execution_role_policy" {
role = "${aws_iam_role.ecs_tasks_execution_role.id}"
role = aws_iam_role.ecs_tasks_execution_role.id
name = "role_policy"

policy = <<EOF
Expand Down Expand Up @@ -103,4 +99,6 @@ resource "aws_iam_role_policy" "execution_role_policy" {
]
}
EOF

}

13 changes: 7 additions & 6 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
output "arn" {
value = "${module.task_definition.arn}"
value = module.task_definition.arn
}

output "task_role_arn" {
value = "${aws_iam_role.task_role.arn}"
value = aws_iam_role.task_role.arn
}

output "task_role_name" {
value = "${aws_iam_role.task_role.name}"
value = aws_iam_role.task_role.name
}

output "task_execution_role_arn" {
value = "${aws_iam_role.ecs_tasks_execution_role.arn}"
value = aws_iam_role.ecs_tasks_execution_role.arn
}

output "task_execution_role_name" {
value = "${aws_iam_role.ecs_tasks_execution_role.name}"
}
value = aws_iam_role.ecs_tasks_execution_role.name
}

13 changes: 7 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,40 @@ variable "env" {
}

variable "release" {
type = "map"
type = map(string)
description = "Metadata about the release"
default = {}
}

variable "family" {
description = "A unique name for your task defintion."
type = "string"
type = string
}

variable "container_definitions" {
description = "A list of valid container definitions provided as a single valid JSON document."
type = "list"
type = list(string)
}

variable "policy" {
description = "A valid IAM policy for the task"
type = "string"
type = string
}

variable "volume" {
description = "Volume block map with 'name' and 'host_path'."
type = "map"
type = map(string)
default = {}
}

variable "assume_role_policy" {
description = "A valid IAM policy for assuming roles - optional"
type = "string"
type = string
default = ""
}

variable "is_test" {
description = "For testing only. Stops the call to AWS for sts"
default = false
}

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 574216f

Please sign in to comment.