-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmerge.tf
31 lines (29 loc) · 1.24 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
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)] : []
model_string = provider::utils::yaml_merge(concat(local.yaml_strings_directories, local.yaml_strings_files, local.model_strings))
model = yamldecode(local.model_string)
user_defaults = { "defaults" : try(local.model["defaults"], {}) }
defaults_string = provider::utils::yaml_merge([file("${path.module}/defaults/defaults.yaml"), yamlencode(local.user_defaults)])
defaults = yamldecode(local.defaults_string)["defaults"]
}
resource "terraform_data" "validation" {
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."
}
}
}
resource "local_sensitive_file" "defaults" {
count = var.write_default_values_file != "" ? 1 : 0
content = local.defaults_string
filename = var.write_default_values_file
}