Is {{template_dir}} no longer recognized or broken in Packer 1.8?

variables {
  template_dir = "{{template_dir}}"
# source goes here
build {
 # sources go here
  provisioner "shell" {
    inline = [
      "echo '{{template_dir}}",
      "echo '${var.template_dir}'"

I have tried many different ways to get {{template_dir}} working in many different builders (vsphere-iso, vsphere-clone, null, etc.) and each time I get an error something like this:

render 'inline': template: root:N:N: executing "root" at <template_dir>: error
calling template_dir: template path not available in:

echo '{{template_dir}}

I am sure I am doing something brain-dead wrong, but I just can’t see it.

Or has it actually been broken in Packer 1.8?

Turns out the template_dir function is not supported anymore in HCL-style templates, and is only supported in “legacy JSON templates”. This fact is not documented clearly.

You have to replace {{ template_dir }} with ${path.root} and it will work fine.