-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
48 lines (36 loc) · 1.29 KB
/
main.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
36
37
38
39
40
41
42
43
44
45
46
47
48
# Format is : //aws-secret:<name>:<key>//
#
locals {
name_key = { for store in var.stores :
store => distinct(flatten(regexall("//@secret/${store}:([^ ]+)//", var.input)))
}
name_key_map = { for store in var.stores :
store => {
for nk in local.name_key[store] : nk => {
name = "${var.prefix}${element(split(":", nk), 0)}"
has_key = (length(split(":", nk)) > 1)
key = (length(split(":", nk)) > 1) ? element(split(":", nk), 1) : null
}
}
}
names = {
for store in var.stores :
store => distinct([
for item in local.name_key_map[store] : item.name
])
}
merged_maps = merge(
local.aws_map,
# When implemented, additional stores will come here
)
secret_map = { for k,v in local.merged_maps :
">//@secret/${k}//" => ((v == null) ? "" : ">\"${v}\"") }
# This throws an error on secret key not existing
errors = [
for k,v in local.merged_maps : (v == null) ?
file("***ERROR: '${k}' secret key not found (prefix = '${var.prefix}') ***") : null
]
words = split(" ", replace(replace(">${var.input}", " ", " >"), "\n", " \n >"))
ewords = [ for word in local.words : lookup(local.secret_map, word, word) ]
result = substr(replace(replace(join(" ", local.ewords), " \n >", "\n"), " >", " "), 1, 100000)
}