Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to merge multiple YAML templates #2324

Open
MarV1908 opened this issue Feb 19, 2025 · 0 comments
Open

How to merge multiple YAML templates #2324

MarV1908 opened this issue Feb 19, 2025 · 0 comments

Comments

@MarV1908
Copy link

Hello,

First, thanks for the great work on Gomplate!

I'm trying to merge a rendered YAML template with one or multiple overrides dynamically. This is similar to how Helm library charts allow merging YAML values.

Goal

  1. Take a base YAML template.
  2. Merge it with one or multiple override templates.
  3. Output the merged result.

This is the Helm "function" i'm trying to mimic :

{{- define "mylibchart.util.merge" -}}
{{- $top := first . -}}
{{- $overrides := fromYaml (include (index . 1) $top) | default (dict) -}}
{{- $tpl := fromYaml (include (index . 2) $top) | default (dict) -}}
{{- toYaml (merge $overrides $tpl) -}}
{{- end -}}

https://helm.sh/docs/topics/library_charts/#create-a-simple-library-chart

Issues Encountered

  • Dynamic Includes: In Helm, include cannot be used inside parentheses, making it tricky to process multiple templates dynamically.
  • Merging Multiple Overrides: I need a way to recursively merge multiple YAML templates while preserving structure.

How would this be done in Gomplate? Is there a recommended approach for merging multiple YAML templates dynamically?

Thanks!

@MarV1908 MarV1908 changed the title How to perform a deep merge over two rendered templates How to merge multiple YAML templates Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant