Error: Missing newline after argument with quotes

Hi Guy’s, I’m new to Terraform and hope someone can help me out.
I am getting the following error when running terraform init …

Error: Missing newline after argument

  on line 13, in data "template_file" "task":
  13:   template = "file ("d:\vcsa100_vCSA_on_ESXi.json")"

An argument definition must end with a newline.

My code is…

data "template_file" "task" {
  template = "file ("d:\vcsa100_vCSA_on_ESXi.json")"

Any suggestions will be much apricated.


Hi @djmc117,

This syntax error appears because you have written a quoted string that has other un-escaped quote marks inside it, and so Terraform thinks "file (" is the entire value of template and doesn’t understand what to do with the rest of the line d:\vcsa100_vCSA_on_ESXi.json")".

The correct syntax for calling the file function would be to not have it in quotes at all. Also, in Terraform we typically use forward slashes in all paths by convention, and use paths relative to the current module so that the module can be portable to other computers that might run different operating systems:

  template = file("${path.module}/vcsa100_vCSA_on_ESXi.json")

With that said, I think it’s also worth noting tha the template_file data source is deprecated and continues to be supported only for backward compatibility with Terraform v0.11 and earlier. Terraform now has a built-in function templatefile which replaces most of the functionality of the template_file data source directly within the Terraform language, without the need for an external plugin.

To use it, you can replace your data "template_file" "task" block with a named local value like this:

locals {
  task_json = templatefile("${path.module}/vcsa100_vCSA_on_ESXi.json", {})

In the example you shared you didn’t include any template variables in template_file, so I mimicked that here by passing an empty object as the second argument to templatefile. Rendering a template without any dynamic data is unusual but valid. If you do intend to use data from elsewhere in your module within the template you can add attributes to that object:

locals {
  task_json = templatefile("${path.module}/vcsa100_vCSA_on_ESXi.json", {
    bucket_arn = aws_s3_bucket.example.arn

To use the templatefile result, you can write local.task_json in your module any place where you might previously have written data.template_file.task.rendered using the data source.

1 Like

I figured this out, I had to change the \ to a /.

…and remove the inner “” i the line Template= it now looks like,

template = “file (d:/scripts/vcsa100_vCSA_on_ESXi.json)”