-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeys.tf
42 lines (34 loc) · 1.02 KB
/
keys.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
locals {
# Build a list of full paths to yaml files
key_file_full_paths = flatten([
for path in var.key_yaml_dirs : [
for file in fileset(path, "**") :
format("%s/%s", path, file)
]
])
# Build a list of decoded yaml file contents
decoded_key_yaml_files = flatten([
for full_path in local.key_file_full_paths :
try(yamldecode(file(full_path)), {})
])
# Extract the ssh keys and their names and store them in a list.
# Each item in the list is all the keys held in a single yaml file.
extracted_keys = flatten([
for key_map in local.decoded_key_yaml_files :
lookup(key_map, "keys", {})
])
# Merge everything into a single map
merged_keys = zipmap(
flatten(
[for item in local.extracted_keys : try(keys(item), [])]
),
flatten(
[for item in local.extracted_keys : try(values(item), [])]
)
)
}
resource "vultr_ssh_key" "key" {
for_each = local.merged_keys != null ? local.merged_keys : {}
name = each.key
ssh_key = each.value.ssh_key
}