[overlay] short syntax for overlaying structures within document
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 167
- PR merge metrics
- No merged PRs in 30d
Description
# Feature request
Add a mechanism to merge computed and YAML values.
## Example use-case
Starting with the following ytt-template (context: the result is a concourse pipeline):
```yaml
#@ def github(repo):
username: ((GITHUB_USER))
password: ((GITHUB_PASS))
#@yaml/text-templated-strings
uri: https://github.com/phil9909/(@= repo @).git
#@ end
resources:
- name: ytt-github
type: git
source: #@ github('ytt')
- name: ytt-lint-github
type: git
source: #@ github('ytt-lint')
```
Now I would like to use the branch `stable` of `ytt-github`, which can be achieved when setting `source.branch` to the desired value.
## Proposed syntax
Intuitively I assumed I could achieve this like so:
```diff
#@ def github(repo):
username: ((GITHUB_USER))
password: ((GITHUB_PASS))
#@yaml/text-templated-strings
uri: https://github.com/phil9909/(@= repo @).git
#@ end
resources:
- name: ytt-github
type: git
source: #@ github('ytt')
+ branch: stable
- name: ytt-lint-github
type: git
source: #@ github('ytt-lint')
```
But ytt gives me `Error: Compiling YAML template 'intutive.yaml': Expected YAML node at line intutive.yaml:12 to have either computed or YAML value, but found both`
An alernative syntax I could imagine is:
```diff
#@ def github(repo):
username: ((GITHUB_USER))
password: ((GITHUB_PASS))
#@yaml/text-templated-strings
uri: https://github.com/phil9909/(@= repo @).git
#@ end
resources:
- name: ytt-github
type: git
- source: #@ github('ytt')
+ source:
+ <<: #@ github('ytt')
+ branch: stable
- name: ytt-lint-github
type: git
source: #@ github('ytt-lint')
```
This uses the standard yaml merge syntax: https://yaml.org/type/merge.html
But ytt rejects this with: `Error: Unmarshaling YAML template 'alternative.yaml': yaml: map merge requires map or sequence of maps as the value`
Contributor guide
Assessment
This issue has not been assessed yet.