-
Notifications
You must be signed in to change notification settings - Fork 1
/
merge.tf
35 lines (31 loc) · 1.27 KB
/
merge.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
35
locals {
yaml_strings_directories = flatten([
for dir in var.yaml_directories : [
for file in fileset(".", "${dir}/*.{yml,yaml}") : file(file)
]
])
yaml_strings_files = [
for file in var.yaml_files : file(file)
]
model_strings = length(keys(var.model)) != 0 ? [yamlencode(var.model)] : []
user_defaults = { "defaults" : try(yamldecode(data.utils_yaml_merge.model.output)["defaults"], {}) }
defaults = yamldecode(data.utils_yaml_merge.defaults.output)["defaults"]
model = yamldecode(data.utils_yaml_merge.model.output)
}
data "utils_yaml_merge" "model" {
input = concat(local.yaml_strings_directories, local.yaml_strings_files, local.model_strings)
lifecycle {
precondition {
condition = length(var.yaml_directories) != 0 || length(var.yaml_files) != 0 || length(keys(var.model)) != 0
error_message = "Either `yaml_directories`,`yaml_files` or a non-empty `model` value must be provided."
}
}
}
data "utils_yaml_merge" "defaults" {
input = [file("${path.module}/defaults/defaults.yaml"), yamlencode(local.user_defaults)]
}
resource "local_sensitive_file" "defaults" {
count = var.write_default_values_file != "" ? 1 : 0
content = data.utils_yaml_merge.defaults.output
filename = var.write_default_values_file
}