diff --git a/docs/functions/yaml_merge.md b/docs/functions/yaml_merge.md index 95a58f7..68168f8 100644 --- a/docs/functions/yaml_merge.md +++ b/docs/functions/yaml_merge.md @@ -10,7 +10,63 @@ description: |- Merge a list of YAML strings into a single YAML string, where maps are deep merged and list entries are compared against existing list entries and if all primitive values match, the entries are deep merged. YAML `!env` tags can be used to resolve values from environment variables. +## Example Usage +```terraform +/* +export ELEM1=value1 +*/ + +locals { + yaml_1 = <<-EOT + root: + elem1: !env ELEM1 + child1: + cc1: 1 + list: + - name: a1 + map: + a1: 1 + b1: 1 + - name: a2 + EOT + + yaml_2 = <<-EOT + root: + elem2: value2 + child1: + cc2: 2 + list: + - name: a1 + map: + a2: 2 + - name: a3 + EOT +} + +output "output" { + value = provider::utils::yaml_merge([local.yaml_1, local.yaml_2]) +} + +/* +output = <<-EOT + list: + - map: + a1: 1 + a2: 2 + b1: 1 + name: a1 + - name: a2 + - name: a3 + root: + child1: + cc1: 1 + cc2: 2 + elem1: value1 + elem2: value2 +EOT +*/ +``` ## Signature diff --git a/examples/functions/yaml_merge/function.tf b/examples/functions/yaml_merge/function.tf new file mode 100644 index 0000000..d41fcc4 --- /dev/null +++ b/examples/functions/yaml_merge/function.tf @@ -0,0 +1,53 @@ +/* +export ELEM1=value1 +*/ + +locals { + yaml_1 = <<-EOT + root: + elem1: !env ELEM1 + child1: + cc1: 1 + list: + - name: a1 + map: + a1: 1 + b1: 1 + - name: a2 + EOT + + yaml_2 = <<-EOT + root: + elem2: value2 + child1: + cc2: 2 + list: + - name: a1 + map: + a2: 2 + - name: a3 + EOT +} + +output "output" { + value = provider::utils::yaml_merge([local.yaml_1, local.yaml_2]) +} + +/* +output = <<-EOT + list: + - map: + a1: 1 + a2: 2 + b1: 1 + name: a1 + - name: a2 + - name: a3 + root: + child1: + cc1: 1 + cc2: 2 + elem1: value1 + elem2: value2 +EOT +*/ \ No newline at end of file