I am trying to template a Levant job but i’m running into issues. I have a YAML object like this:
group:
network:
ports:
- http:
to: 9999
from: 9999
- statsd:
to: 9998
from: 9995
and I’d like to translate this to a range of ports:
group "[[ .job.job_name ]].group" {
[[ range $ports := .job.group.network.ports ]]
[[ range $parent_key := $ports ]]
port [[ . ]] {[[ range $k, $v := $parent_key ]]
[[ $k ]] = [[ $v ]][[ end ]]
}
[[ end ]]
[[ end ]]
I tried a bunch of stuff to get this to work including trying to use index
however i’m not able to properly reference the parent name to reference the ports.
I end up with output like:
port map[from:9999 to:9999] {
from = 9999
to = 9999
}
port map[from:9995 to:9998] {
from = 9995
to = 9998
}
Is there a simple way of working with YAML / Levant and templating objects like ports?
Thank you!