Today I Learned

Use templatefile function instead of template_file

Since terraform v 0.12 it’s recommended to use templatefile(path, vars) function instead of data source template_file.

As data source provider has it’s own copy of template file engine that is separate from the Terraform itself. The engine depends on the version of Terraform that the provider was compiled with and not the one run on your system.

Using templatefile(path, vars) function will give you more consistent results as it depends on the version of Terraform you are using.

Example usage:

templatefile("${path.module}/backends.tmpl", { port = 8080, ip_addrs = ["10.0.0.1", "10.0.0.2"] })

Source:

https://www.terraform.io/docs/configuration/functions/templatefile.html https://www.terraform.io/docs/providers/template/d/file.html