Templates to be re-rendered when using timestampe

I have a template the generates dns zone files. We have been using the timestamp function to generated the new serial. Unfortunately, this causes the template to be continuously rendered. Makes sense. The in-memory version is different than the file on the filesystem

Essentially, I would like to generated a new file when a key changes and increment the serial number. Any thoughts on how someone might work around this issue?

The template I’m using:

{- $ts := timestamp "unix" -}}
{{- $dc := index (env "DC" -}}
{{- $zonekey := printf "service/app/%s/zone/example.com@%s" (env "ENVIRONMENT") $dc -}}
{{- $out := key $zonekey -}}
{{- $out = $out | replaceAll "[[TIMESTAMP]]" $ts -}}
{{- $out -}}

Cheers

As an alternative is is possible, to use the consul keys modify index as an alternative. I have not been able to identify a means of accessing it.

I have confirmed the ModifyIndex is not changing:

CreateIndex 140007641 Flags 0 Key service/app/dev/zone/example.com LockIndex 0 ModifyIndex 141491488