Skip to content

Commit

Permalink
Add function example
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Jun 9, 2024
1 parent b9ee6f2 commit b6d09ec
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
56 changes: 56 additions & 0 deletions docs/functions/yaml_merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
53 changes: 53 additions & 0 deletions examples/functions/yaml_merge/function.tf
Original file line number Diff line number Diff line change
@@ -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
*/

0 comments on commit b6d09ec

Please sign in to comment.