Vault agent templates - how to get secret previous version

Hi,

I try to create template which will create file contain current and previous secret version.
I figure out that i can pull current version number from secret metadata. Then I can tansform it and use subtract to find previous version number. In this point I have information about version i want to get but i can’t figure out how to pull it. I theory it’s easy and i just need to add ?version= when i’m pulling secret from Vault however I can’t find any working examples. Maybe someone on forum have more experiance and know how to do it? I will be appreciated for any clues :).

this is what i try to do:

#This is working:
{{- with secret "kv/test" -}}
  {{- $cversion := .Data | toJSON | parseJSON}}
  {{- $pversion := $cversion.metadata.version | subtract 1 }}
---
 cv: {{ $cversion.metadata.version }}
 pv: {{ $pversion }}

 {{  .Data.data.test }}
---
#this part is not working - {{ $pversion }} is interpolated as ''
{{- with secret "kv/test?version={{ $pversion }}" -}}
   {{  .Data.data.test }}
{{- end -}}
{{- end -}}