Getting "Invalid template directive" - How do I handle a template with special syntax?

I have a template for a Nomad job that includes the following template stanza:

template {
  data = <<EOH
index => "index=%{+YYYY.MM.dd}"
user => "{{ key "some/consul/key" }}"
  destination = "local/file.yml"

nomad run results in the following error:

Error getting job struct: Failed to parse using HCL 2.  Use the HCL 1 parser with `nomad run -hcl1`, or address the following issues:
stdin:52,31-32: Invalid template directive; A template directive keyword ("if", "for", etc) is expected at the beginning of a %{ sequence.

How do I create a file using templating that contains %{ without having it interpreted and resulting in this failure? I’m guessing there is some heredoc or escaping that will solve this, but I haven’t figured it out yet. Any suggestions would be greatly appreciated. Thanks!

Also faced the same problem. @jcouvret did you manage to solve the problem?

Honestly, I don’t even remember solving this, but I checked now and my code looks like this:

index => "index-%%{+YYYY.MM.dd}"

I think maybe the double percentage signs does some sort of escaping?? I wish I had an actual answer for you, but I know that the job I’m copying this from works, so hopefully this works for you as well.


Thanks a lot! It’s working. But that doesn’t solve my problem with getting data from Filebeat to logstash, but that’s another story.