|
1 | 1 | locals { |
2 | | - // Find the greatest depth through the maps |
3 | | - greatest_depth = max(concat([ |
4 | | - for mod in local.modules: |
5 | | - concat([ |
6 | | - for i in range(0, length(var.maps)): |
7 | | - [ |
8 | | - for f in mod[i].fields: |
9 | | - length(f["path"]) |
10 | | - ] |
11 | | - ]...) |
12 | | - ]...)...) |
| 2 | + // Find the greatest depth through the maps |
| 3 | + greatest_depth = max(concat([ |
| 4 | + for mod in local.modules : |
| 5 | + concat([ |
| 6 | + for i in range(0, length(var.maps)) : |
| 7 | + [ |
| 8 | + for f in mod[i].fields : |
| 9 | + length(f["path"]) |
| 10 | + ] |
| 11 | + ]...) |
| 12 | + ]...)...) |
13 | 13 |
|
14 | | - // For each input map, convert it to a single-level map with a unique key for every nested value |
15 | | - fields_json = [ |
16 | | - for i in range(0, length(var.maps)): |
17 | | - merge([ |
18 | | - for j in range(0, local.greatest_depth): |
19 | | - { |
20 | | - for f in local.modules[j][i].fields: |
21 | | - jsonencode(f.path) => f |
22 | | - } |
23 | | - ]...) |
24 | | - ] |
| 14 | + // For each input map, convert it to a single-level map with a unique key for every nested value |
| 15 | + fields_json = [ |
| 16 | + for i in range(0, length(var.maps)) : |
| 17 | + merge([ |
| 18 | + for j in range(0, local.greatest_depth) : |
| 19 | + { |
| 20 | + for f in local.modules[j][i].fields : |
| 21 | + jsonencode(f.path) => f |
| 22 | + } |
| 23 | + ]...) |
| 24 | + ] |
25 | 25 |
|
26 | | - // Merge the maps using the standard merge function, which will cause higher-precedence map values to overwrite lower-precedence values |
27 | | - merged_map = merge(local.fields_json...) |
| 26 | + // Merge the maps using the standard merge function, which will cause higher-precedence map values to overwrite lower-precedence values |
| 27 | + merged_map = merge(local.fields_json...) |
28 | 28 |
|
29 | | - // Split the merged fields into segments for each depth |
30 | | - merged_fields_by_depth = { |
31 | | - for depth in range(0, local.greatest_depth): |
32 | | - depth => { |
33 | | - for key in keys(local.merged_map): |
34 | | - key => local.merged_map[key] |
35 | | - if length(local.merged_map[key].path) == depth + 1 |
36 | | - } |
37 | | - } |
38 | | - // The lowest level of the re-assembled map is special and not part of the auto-generated depth.tf file |
39 | | - m0 = { |
40 | | - for field in local.merged_fields_by_depth[0]: |
41 | | - field.path[0] => {final_val = field.value, sub_val = lookup(local.m1, field.key, null)}[field.is_final ? "final_val" : "sub_val"] |
| 29 | + // Split the merged fields into segments for each depth |
| 30 | + merged_fields_by_depth = { |
| 31 | + for depth in range(0, local.greatest_depth) : |
| 32 | + depth => { |
| 33 | + for key in keys(local.merged_map) : |
| 34 | + key => local.merged_map[key] |
| 35 | + if length(local.merged_map[key].path) == depth + 1 |
42 | 36 | } |
| 37 | + } |
| 38 | + // The lowest level of the re-assembled map is special and not part of the auto-generated depth.tf file |
| 39 | + m0 = { |
| 40 | + for field in local.merged_fields_by_depth[0] : |
| 41 | + field.path[0] => { final_val = field.value, sub_val = lookup(local.m1, field.key, null) }[field.is_final ? "final_val" : "sub_val"] |
| 42 | + } |
43 | 43 | } |
44 | | - |
| 44 | + |
45 | 45 | // Check to make sure the highest level module has no remaining values that weren't recursed through |
46 | 46 | module "asset_sufficient_levels" { |
47 | | - source = "Invicton-Labs/assertion/null" |
48 | | - version = "0.1.1" |
49 | | - error_message = "Deepmerge has recursed to insufficient depth (${length(local.modules)} levels is not enough)" |
50 | | - condition = concat([ |
51 | | - for i in range(0, length(var.maps)): |
52 | | - local.modules[length(local.modules) - 1][i].remaining |
53 | | - ]...) == [] |
| 47 | + source = "Invicton-Labs/assertion/null" |
| 48 | + version = "0.2.1" |
| 49 | + error_message = "Deepmerge has recursed to insufficient depth (${length(local.modules)} levels is not enough)" |
| 50 | + condition = concat([ |
| 51 | + for i in range(0, length(var.maps)) : |
| 52 | + local.modules[length(local.modules) - 1][i].remaining |
| 53 | + ]...) == [] |
54 | 54 | } |
55 | 55 |
|
56 | 56 | // Use this from a DIFFERENT terraform project to generate a new file with a different max depth |
|
0 commit comments