Accessing values of Maps nested in an array #1722
Closed
Kalimero66
started this conversation in
General
Replies: 2 comments 1 reply
-
|
Anybody ? |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
well ... no feedback ... closing this topic. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Bonjour,
I'm stuck with a simple problem when trying to use gomplate on Helmfile input and I was wondering if someone can help.
My datasource file is a typical Helmfile input as follow:
Is it possible to access
k4value (.iev4) in one line ?I know I could potentially could just convert
valuesinto a map of maps instead but there must be a better way withgomplatethat I'm just not seeing.Here are my files if anyone interested.
.gomplate.yaml:
ds.yaml:
valuesis an array of Maps , I guess I need to first find the index ofmyMap2invaluesbefore accessingk4.As I have many (30+) Maps under
values, I use a nested template to find the index of the map in the array but I find it overkilled (and I haven't to cover any corner case yet). Like I said there must be a better way.in.yaml.gotmpl:
{{- $findMapIndex := ` {{- $k := .key -}} {{- range $idx, $val := .list -}} {{- if coll.Has $val $k -}} {{- printf "%d" $idx -}} {{- break -}} {{- end -}} {{- end -}} ` -}} {{- $envName := (index (keys (ds "env").environments) 0) }} {{- $env := (index (ds "env").environments $envName) }} {{- $values := (index $env "values") }} {{- $dict := coll.Dict "key" "myMap2" "list" $values }} {{- $i := conv.ToInt (tpl $findMapIndex $dict) }} {{ printf "Value for k4 is: %s" (index $values $i).myMap2.k4 }} {{- $dict := coll.Dict "key" "myMap1" "list" $values }} {{- $j := conv.ToInt (tpl $findMapIndex $dict) }} {{ printf "Value for k1 is: %s" (index $values $j).myMap1.k1 }}Beta Was this translation helpful? Give feedback.
All reactions