Search code examples
terraformterraform-template-file

Adding a long content using End of text string(EOT) in terraform is throwing error


I want to add a content to the file using terraform using a local provider. Here is the example script which I am using

terraform {
    required_version = "~>0.13"
    required_providers {
        local = "~>1.4"
    }
}

resource "local_file" "literature" {
 filename = "art_of_war.txt"
 content = <<EOT 
        Hello 
        world 
 EOT
}

I am getting the following error Expected the start of an expression, but found an invalid expression token. .Can you please point what might be error.


Solution

  • It seems that in your example you were using tabs instead of spaces (or you have it configured in your editor). I recreated your example with using only spaces and it worked. Here's the code snippet that works:

    resource "local_file" "literature" {
     filename = "art_of_war.txt"
     content = <<EOT
      Hello
      World
    EOT
    }
    

    Note that EOT is left-aligned to the same level as resource.

    EDIT: Actually, it seems there's a whitespace after the <<EOT, if you delete it it should work.