Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKotowick committed Aug 12, 2021
1 parent e0c5416 commit 633cb9b
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,96 @@ This module performs a deep map merge of standard Terraform maps/objects. It is
It functions by "flattening" each input map into a map of depth 1 where each key is the full path to the value in question. It then uses the standard merge function on these flat maps, and finally it re-builds the map structure in reverse order.

**Note:** Lists will be overwritten. Only maps are merged.

## Usage
```
locals {
map1 = {
key1-1 = {
key1-1-1 = "value1-1-1"
key1-1-2 = "value1-1-2"
key1-1-3 = {
key1-1-3-1 = "value1-1-3-1"
key1-1-3-2 = "value1-1-3-2"
}
}
key1-2 = "value1-2"
key1-3 = {
key1-3-1 = "value1-3-1"
key1-3-2 = "value1-3-2"
}
}
map2 = {
key1-1 = {
key1-1-1 = "value1-1-1(overwrite)"
key1-1-3 = {
key1-1-3-2 = "value1-1-3-2(overwrite)"
key1-1-3-3 = {
key1-1-3-3-1 = "value1-1-3-3-1"
}
}
key1-1-4 = "value1-1-4"
}
key1-2 = {
key1-2-1 = "value1-2-1"
key1-2-2 = "value1-2-2"
key1-2-3 = {
key1-2-3-1 = "value1-2-3-1"
}
}
key1-3 = "value1-3(overwrite)"
}
map3 = {
key1-3 = "value1-3(double-overwrite)"
key1-2 = {
key1-2-3 = {
key1-2-3-2 = "value1-2-3-2"
}
}
}
}
module "deepmerge" {
source = "../../"
maps = [
local.map1,
local.map2,
local.map3
]
}
output "merged" {
description = "The merged map."
value = module.deepmerge.merged
}
```

Output:
```
merged = {
"key1-1" = {
"key1-1-1" = "value1-1-1(overwrite)"
"key1-1-2" = "value1-1-2"
"key1-1-3" = {
"key1-1-3-1" = "value1-1-3-1"
"key1-1-3-2" = "value1-1-3-2(overwrite)"
"key1-1-3-3" = {
"key1-1-3-3-1" = "value1-1-3-3-1"
}
}
"key1-1-4" = "value1-1-4"
}
"key1-2" = {
"key1-2-1" = "value1-2-1"
"key1-2-2" = "value1-2-2"
"key1-2-3" = {
"key1-2-3-1" = "value1-2-3-1"
"key1-2-3-2" = "value1-2-3-2"
}
}
"key1-3" = "value1-3(double-overwrite)"
}
```

0 comments on commit 633cb9b

Please sign in to comment.