Skip to content

Commit 1b523b1

Browse files
committedAug 7, 2020
Migrated to v0.12.
1 parent e5634c6 commit 1b523b1

12 files changed

+89
-53
lines changed
 

‎common_vars.tf

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
variable "tags" {
2+
type = map
23
default = {}
34
}
5+

‎depends_on.tf

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# depends_on workaround
22

3-
variable "depends_on" {
3+
variable "module_depends_on" {
44
description = "Helper variable to simulate depends_on for terraform modules"
5-
default = []
5+
type = list
6+
default = [""]
67
}
78

8-
output "depends_on" {
9-
value = "${var.depends_on}"
9+
output "module_depends_on" {
10+
value = "${var.module_depends_on}"
11+
}
12+
13+
resource "null_resource" "module_depends_on" {
14+
triggers = {
15+
value = length(var.module_depends_on)
16+
}
1017
}

‎main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
resource "aws_ecr_repository" "main" {
2-
name = "${var.name}"
2+
name = var.name
33
}
4+

‎modules/deployment/common_vars.tf

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
variable "tags" {
2+
type = map
23
default = {}
34
}
5+

‎modules/deployment/depends_on.tf

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# depends_on workaround
22

3-
variable "depends_on" {
3+
variable "module_depends_on" {
44
description = "Helper variable to simulate depends_on for terraform modules"
5-
default = []
5+
type = list
6+
default = [""]
67
}
78

8-
output "depends_on" {
9-
value = "${var.depends_on}"
9+
output "module_depends_on" {
10+
value = "${var.module_depends_on}"
11+
}
12+
13+
resource "null_resource" "module_depends_on" {
14+
triggers = {
15+
value = length(var.module_depends_on)
16+
}
1017
}

‎modules/deployment/main.tf

+36-31
Original file line numberDiff line numberDiff line change
@@ -6,89 +6,94 @@ resource "random_string" "build_name" {
66
}
77

88
locals {
9-
build = "${file(format("%s/%s", var.source_dir, "/Dockerfile"))}"
9+
build = file(format("%s/%s", var.source_dir, "/Dockerfile"))
1010
}
1111

1212
resource "null_resource" "task_build" {
13-
triggers {
14-
build = "${local.build}"
13+
triggers = {
14+
build = local.build
1515
}
1616

1717
provisioner "local-exec" {
18-
working_dir = "${var.source_dir}"
18+
working_dir = var.source_dir
1919

2020
command = <<EOF
2121
docker build -t ${random_string.build_name.result} .
2222
EOF
23+
2324
}
2425
}
2526

2627
resource "null_resource" "task_tag" {
27-
triggers {
28-
build = "${local.build}"
28+
triggers = {
29+
build = local.build
2930
}
3031

3132
provisioner "local-exec" {
32-
working_dir = "${var.source_dir}"
33+
working_dir = var.source_dir
3334

3435
command = <<EOF
3536
docker tag ${random_string.build_name.result}:latest ${var.repository_url}:latest
3637
EOF
38+
3739
}
3840

39-
depends_on = ["null_resource.task_build"]
41+
depends_on = [null_resource.task_build]
4042
}
4143

4244
resource "null_resource" "task_push" {
43-
count = "${var.assume_role_arn == "" ? 1 : 0}"
45+
count = var.assume_role_arn == "" ? 1 : 0
4446

45-
triggers {
46-
build = "${local.build}"
47+
triggers = {
48+
build = local.build
4749
}
4850

4951
provisioner "local-exec" {
50-
working_dir = "${var.source_dir}"
52+
working_dir = var.source_dir
5153

5254
environment = {
53-
REGISTRY_ID = "${var.registry_id}"
54-
REPOSITORY_URL = "${var.repository_url}"
55+
REGISTRY_ID = var.registry_id
56+
REPOSITORY_URL = var.repository_url
5557
}
5658

5759
command = <<EOF
58-
aws ecr get-login --no-include-email --registry-ids "$$REGISTRY_ID" | /bin/sh
59-
docker push "$$REPOSITORY_URL:latest"
60+
aws ecr get-login --no-include-email --registry-ids "$REGISTRY_ID" | /bin/sh
61+
docker push "$REPOSITORY_URL:latest"
6062
EOF
63+
6164
}
6265

63-
depends_on = ["null_resource.task_tag"]
66+
depends_on = [null_resource.task_tag]
6467
}
6568

6669
resource "null_resource" "task_push_with_role" {
67-
count = "${var.assume_role_arn == "" ? 0 : 1}"
70+
count = var.assume_role_arn == "" ? 0 : 1
6871

69-
triggers {
70-
build = "${local.build}"
72+
triggers = {
73+
build = local.build
7174
}
7275

7376
provisioner "local-exec" {
74-
working_dir = "${var.source_dir}"
77+
working_dir = var.source_dir
7578

7679
environment = {
77-
REGISTRY_ID = "${var.registry_id}"
78-
REPOSITORY_URL = "${var.repository_url}"
79-
ASSUME_ROLE_ARN = "${var.assume_role_arn}"
80+
REGISTRY_ID = var.registry_id
81+
REPOSITORY_URL = var.repository_url
82+
ASSUME_ROLE_ARN = var.assume_role_arn
8083
}
8184

8285
command = <<EOF
83-
CONFIG=$$(aws sts assume-role --role-arn "$$ASSUME_ROLE_ARN" --role-session-name tf-tmp --output json)
84-
export AWS_ACCESS_KEY_ID=$$(echo "$$CONFIG" | jq -r .Credentials.AccessKeyId)
85-
export AWS_SECRET_ACCESS_KEY=$$(echo "$$CONFIG" | jq -r .Credentials.SecretAccessKey)
86-
export AWS_SESSION_TOKEN=$$(echo "$$CONFIG" | jq -r .Credentials.SessionToken)
86+
CONFIG=$(aws sts assume-role --role-arn "$ASSUME_ROLE_ARN" --role-session-name tf-tmp --output json)
87+
export AWS_ACCESS_KEY_ID=$(echo "$CONFIG" | jq -r .Credentials.AccessKeyId)
88+
export AWS_SECRET_ACCESS_KEY=$(echo "$CONFIG" | jq -r .Credentials.SecretAccessKey)
89+
export AWS_SESSION_TOKEN=$(echo "$CONFIG" | jq -r .Credentials.SessionToken)
8790
88-
aws ecr get-login --no-include-email --registry-ids "$$REGISTRY_ID" | /bin/sh
89-
docker push "$$REPOSITORY_URL:latest"
91+
aws ecr get-login --no-include-email --registry-ids "$REGISTRY_ID" | /bin/sh
92+
docker push "$REPOSITORY_URL:latest"
9093
EOF
94+
9195
}
9296

93-
depends_on = ["null_resource.task_tag"]
97+
depends_on = [null_resource.task_tag]
9498
}
99+

‎modules/deployment/outputs.tf

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
output "source_dir" {
2-
value = "${var.source_dir}"
2+
value = var.source_dir
33
}
44

55
output "repository_url" {
6-
value = "${var.repository_url}"
6+
value = var.repository_url
77
}
88

99
output "registry_id" {
10-
value = "${var.registry_id}"
10+
value = var.registry_id
1111
}
1212

1313
output "assume_role_arn" {
14-
value = "${var.assume_role_arn}"
14+
value = var.assume_role_arn
1515
}
16+

‎modules/deployment/variables.tf

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
variable "source_dir" {
22
description = "The function folder to be archived"
3-
type = "string"
3+
type = string
44
}
55

66
variable "repository_url" {
77
description = "The ecs repository url"
8-
type = "string"
8+
type = string
99
}
1010

1111
variable "registry_id" {
1212
description = "The ecs registry id"
13-
type = "string"
13+
type = string
1414
}
1515

1616
variable "assume_role_arn" {
1717
description = "Role to assume"
18-
type = "string"
18+
type = string
1919
default = ""
2020
}
21+

‎modules/deployment/versions.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}

‎outputs.tf

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
output "name" {
2-
value = "${aws_ecr_repository.main.name}"
2+
value = aws_ecr_repository.main.name
33
}
44

55
output "arn" {
6-
value = "${aws_ecr_repository.main.arn}"
6+
value = aws_ecr_repository.main.arn
77
}
88

99
output "url" {
10-
value = "${aws_ecr_repository.main.repository_url}"
10+
value = aws_ecr_repository.main.repository_url
1111
}
1212

1313
output "registry_id" {
14-
value = "${aws_ecr_repository.main.registry_id}"
14+
value = aws_ecr_repository.main.registry_id
1515
}
16+

‎variables.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
variable "name" {
22
description = "The name for this repository"
3-
type = "string"
3+
type = string
44
}
5+

‎versions.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}

0 commit comments

Comments
 (0)
Please sign in to comment.