Skip to content

Commit

Permalink
Update internal modules, license, and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKotowick committed Jul 30, 2021
1 parent f07e784 commit 9966b59
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 45 deletions.
2 changes: 2 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Copyright (c) 2021 [Invicton Labs](https://invictonlabs.com)

# Creative Commons Attribution 4.0 International

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.
Expand Down
90 changes: 45 additions & 45 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
locals {
// Find the greatest depth through the maps
greatest_depth = max(concat([
for mod in local.modules:
concat([
for i in range(0, length(var.maps)):
[
for f in mod[i].fields:
length(f["path"])
]
]...)
]...)...)
// Find the greatest depth through the maps
greatest_depth = max(concat([
for mod in local.modules :
concat([
for i in range(0, length(var.maps)) :
[
for f in mod[i].fields :
length(f["path"])
]
]...)
]...)...)

// For each input map, convert it to a single-level map with a unique key for every nested value
fields_json = [
for i in range(0, length(var.maps)):
merge([
for j in range(0, local.greatest_depth):
{
for f in local.modules[j][i].fields:
jsonencode(f.path) => f
}
]...)
]
// For each input map, convert it to a single-level map with a unique key for every nested value
fields_json = [
for i in range(0, length(var.maps)) :
merge([
for j in range(0, local.greatest_depth) :
{
for f in local.modules[j][i].fields :
jsonencode(f.path) => f
}
]...)
]

// Merge the maps using the standard merge function, which will cause higher-precedence map values to overwrite lower-precedence values
merged_map = merge(local.fields_json...)
// Merge the maps using the standard merge function, which will cause higher-precedence map values to overwrite lower-precedence values
merged_map = merge(local.fields_json...)

// Split the merged fields into segments for each depth
merged_fields_by_depth = {
for depth in range(0, local.greatest_depth):
depth => {
for key in keys(local.merged_map):
key => local.merged_map[key]
if length(local.merged_map[key].path) == depth + 1
}
}
// The lowest level of the re-assembled map is special and not part of the auto-generated depth.tf file
m0 = {
for field in local.merged_fields_by_depth[0]:
field.path[0] => {final_val = field.value, sub_val = lookup(local.m1, field.key, null)}[field.is_final ? "final_val" : "sub_val"]
// Split the merged fields into segments for each depth
merged_fields_by_depth = {
for depth in range(0, local.greatest_depth) :
depth => {
for key in keys(local.merged_map) :
key => local.merged_map[key]
if length(local.merged_map[key].path) == depth + 1
}
}
// The lowest level of the re-assembled map is special and not part of the auto-generated depth.tf file
m0 = {
for field in local.merged_fields_by_depth[0] :
field.path[0] => { final_val = field.value, sub_val = lookup(local.m1, field.key, null) }[field.is_final ? "final_val" : "sub_val"]
}
}

// Check to make sure the highest level module has no remaining values that weren't recursed through
module "asset_sufficient_levels" {
source = "Invicton-Labs/assertion/null"
version = "0.1.1"
error_message = "Deepmerge has recursed to insufficient depth (${length(local.modules)} levels is not enough)"
condition = concat([
for i in range(0, length(var.maps)):
local.modules[length(local.modules) - 1][i].remaining
]...) == []
source = "Invicton-Labs/assertion/null"
version = "0.2.1"
error_message = "Deepmerge has recursed to insufficient depth (${length(local.modules)} levels is not enough)"
condition = concat([
for i in range(0, length(var.maps)) :
local.modules[length(local.modules) - 1][i].remaining
]...) == []
}

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

0 comments on commit 9966b59

Please sign in to comment.