I'm trying to add a map to an array of maps in ytt to modify a YAML doc.
I tried the below but it errors out and says it expects a map but getting an array.
https://gist.github.com/amalagaura/c8b5c7c92402120ed76dec95dfafb276
---
id: 1
type: book
awards:
books:
- id: 1
title: International Botev
reviewers:
- id: 2
name: PersonB
- id: 2
title: Dayton Literary Peace Prize
reviewers:
- id: 3
name: PersonC
#! How do I add a map to an array of maps?
#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.all
---
awards:
books:
#@overlay/match by=overlay.all, expects="1+"
#@overlay/match missing_ok=True
reviewers:
#@overlay/append
- id: 1
name: PersonA
You were really close in your solution, all you really needed was to make
reviewersan array item. If you want to be able to add reviewers to a book that does not have that key, then you will have to add a matcher on the array item and the map item; a gist is included below to see this behavior overlay in action. If you have more than one#@overlay/matchannotation on the same item, the last one wins. There are plans to improve this behavior: https://github.com/k14s/ytt/issues/114.https://get-ytt.io/#gist:https://gist.github.com/gcheadle-vmware/a6243ee73fa5cc139dba870690eb15c5