Skip to content

Commit 9966b59

Browse files
committed
Update internal modules, license, and formatting
1 parent f07e784 commit 9966b59

File tree

2 files changed

+47
-45
lines changed

2 files changed

+47
-45
lines changed

LICENSE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
### Copyright (c) 2021 [Invicton Labs](https://invictonlabs.com)
2+
13
# Creative Commons Attribution 4.0 International
24

35
Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible.

main.tf

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
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+
]...)...)
1313

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+
]
2525

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...)
2828

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
4236
}
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+
}
4343
}
44-
44+
4545
// Check to make sure the highest level module has no remaining values that weren't recursed through
4646
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+
]...) == []
5454
}
5555

5656
// Use this from a DIFFERENT terraform project to generate a new file with a different max depth

0 commit comments

Comments
 (0)