This repository has been archived by the owner on Nov 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
outputs.tf
34 lines (28 loc) · 2.14 KB
/
outputs.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
# The following hacks are required to overcome TF automatic type conversions which lead to issues with the resulting json types.
# Conversion happens by using the built-in `replace` function in this order:
# - Convert `""`, `{}`, `[]`, and `[""]` to `null`
# - Convert `"true"` and `"false"` to `true` and `false`
# - Convert quoted numbers (e.g. `"123"`) to `123`.
# Environment variables are kept as strings.
locals {
encoded_environment_variables = "${jsonencode(local.environment)}"
encoded_secrets = "${length(local.secrets) > 0 ? jsonencode(local.secrets) : "null"}"
encoded_cpu = "${var.container_cpu > 0 ? var.container_cpu : "null"}"
encoded_memory = "${var.container_memory > 0 ? var.container_memory : "null"}"
encoded_memory_reservation = "${var.container_memory_reservation > 0 ? var.container_memory_reservation : "null"}"
encoded_container_definition = "${replace(replace(replace(jsonencode(local.container_definition), "/(\\[\\]|\\[\"\"\\]|\"\"|{})/", "null"), "/\"(true|false)\"/", "$1"), "/\"(-?[0-9]+\\.?[0-9]*)\"/", "$1")}"
json_with_environment = "${replace(local.encoded_container_definition, "/\"environment_sentinel_value\"/", local.encoded_environment_variables)}"
json_with_secrets = "${replace(local.json_with_environment, "/\"secrets_sentinel_value\"/", local.encoded_secrets)}"
json_with_cpu = "${replace(local.json_with_secrets, "/\"cpu_sentinel_value\"/", local.encoded_cpu)}"
json_with_memory = "${replace(local.json_with_cpu, "/\"memory_sentinel_value\"/", local.encoded_memory)}"
json_with_memory_reservation = "${replace(local.json_with_memory, "/\"memory_reservation_sentinel_value\"/", local.encoded_memory_reservation)}"
json_map = "${local.json_with_memory_reservation}"
}
output "json" {
description = "JSON encoded container definitions for use with other terraform resources such as aws_ecs_task_definition."
value = "[${local.json_map}]"
}
output "json_map" {
description = "JSON encoded container definitions for use with other terraform resources such as aws_ecs_task_definition."
value = "${local.json_map}"
}