# Render template variables stored in KV

**URL:** <https://discuss.hashicorp.com/t/render-template-variables-stored-in-kv/34949>\
**Category:** Consul\
**Tags:** consul-template\
**Created:** [January 29, 2022, 11:24am UTC](https://discuss.hashicorp.com/t/render-template-variables-stored-in-kv/34949 "2022-01-29T11:24:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/nicolas/32/24238_2.png) [@Nicolas](https://discuss.hashicorp.com/u/Nicolas)\
**Post date:** [January 29, 2022, 11:24am UTC](https://discuss.hashicorp.com/t/render-template-variables-stored-in-kv/34949/1 "2022-01-29T11:24:28Z")

</div>

Hello everyone,

Is it possible using consul-template to render a template stored in consul KV?

I have YAML coming from a current workflow stored in KV. I’m able to render a configuration file from that YAML, but I’d like to interpolate the variables (references to services) present in that YAML.

It looks like consul-templaterb is able to do that, using render\_from\_string ([https://github.com/criteo/consul-templaterb/blob/master/TemplateAPI.md#render\_from\_stringtemplate\_to\_render-params](https://github.com/criteo/consul-templaterb/blob/master/TemplateAPI.md#render_from_stringtemplate_to_render-params)

Thanks!  
Nicolas

---

<div class="post-metadata">

**Author:** ![eikenb](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/eikenb/32/1173_2.png) [@eikenb](https://discuss.hashicorp.com/u/eikenb)\
**Post date:** [February 1, 2022, 12:47am UTC](https://discuss.hashicorp.com/t/render-template-variables-stored-in-kv/34949/2 "2022-02-01T00:47:40Z")

</div>

Currently consul-template doesn’t support templates stored in Consul’s KV store. It works with local (to it) files. There is nothing theoretically preventing some level of support for storing templates in Consul. Please consider filing a feature request ticket or a PR for this functionality.

You might be able to get what you’re after with consul-template by layering it. Have one consul-template grab that value and render it to a file, then have another consul-template monitor that file and render it again to interpolate those variables.

Hope this helps and thanks for your interest!

---

<div class="post-metadata">

**Author:** ![Nicolas](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/nicolas/32/24238_2.png) [@Nicolas](https://discuss.hashicorp.com/u/Nicolas)\
**Post date:** [February 2, 2022, 5:49pm UTC](https://discuss.hashicorp.com/t/render-template-variables-stored-in-kv/34949/3 "2022-02-02T17:49:19Z")

</div>

> [@eikenb](#):
>
> Currently consul-template doesn’t support templates stored in Consul’s KV store. It works with local (to it) files. There is nothing theoretically preventing some level of support for storing templates in Consul. Please consider filing a feature request ticket or a PR for this functionality.
> 
> You might be able to get what you’re after with consul-template by layering it. Have one consul-template grab that value and render it to a file, then have another consul-template monitor that file and render it again to interpolate those variables.

Thanks for your nice solution! I won’t file a feature request, since it’s only a temporary need and the workaround is sufficient.

---

<div class="post-metadata">

**Author:** ![Material-Scientist](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/material-scientist/32/39571_2.png) [@Material-Scientist](https://discuss.hashicorp.com/u/Material-Scientist)\
**Post date:** [June 29, 2025, 8:59pm UTC](https://discuss.hashicorp.com/t/render-template-variables-stored-in-kv/34949/4 "2025-06-29T20:59:21Z")

</div>

I also arrived at that, but it doesn’t work.

```hcl
      # Consul HCL Template
      artifact {
        source = "http://consul.service.consul:8500/v1/kv/config/templates/consul.hcl.tpl?raw"
        destination = "local"
        headers {
          X-Consul-Token = "${CONSUL_HTTP_TOKEN}"
        }
      }
  
      template {
        data = "{{ key \"config/templates/consul.hcl.tpl\" }}\n# Updated: {{ timestamp }}"
        destination = "local/consul.hcl.tpl"
        change_mode = "noop" # Don't restart, just update file
      }
  
      template {
        source = "local/consul.hcl.tpl"
        destination = "local/consul.hcl"
      }

```

The artifact is required to fetch the file such that the 2nd template block can pick up the config via `source`.

The 1st template block is required to trigger an update to the tpl file (using `change_mode = "noop"` here).

This only works the first time, where the artifact is grabbed and the 2nd template renders it (artifact is only downloaded on task start, but not restart).

However, on subsequent updates to the tpl on Consul KV, only the tpl file is updated, but the 2nd template doesn’t re-render from it for some reason.

You can see here in the screenshot that the tpl file was updated 8min ago (upon me changing the value in Consul KV), but the hcl file did not register the change and therefore did not re-render:

 ![image](https://global.discourse-cdn.com/hashicorp/original/3X/a/b/abcb7c661a0d7dad0d617af0499bca6716757327.png)

I even tried manually editing the tpl file at `/opt/nomad/alloc/969b4514-c61e-1629-d836-bb2d4b58b896/config-reload/local/consul.hcl.tpl`, but the 2nd template still didn’t re-render.

I’m not sure if this is a bug or not. I don’t understand why the 2nd template doesn’t register the file change.
