在 terraform 中使用文本字符串结尾(EOT)添加长内容会引发错误

sat*_*ish 2 terraform terraform-template-file

我想使用本地提供商使用 terraform 将内容添加到文件中。这是我正在使用的示例脚本

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

resource "local_file" "literature" {
 filename = "art_of_war.txt"
 content = <<EOT 
        Hello 
        world 
 EOT
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误 Expected the start of an expression, but found an invalid expression token.。您能指出可能出现的错误吗?

Mar*_*o E 10

看来在您的示例中您使用的是制表符而不是空格(或者您在编辑器中配置了它)。我仅使用空格重新创建了您的示例,并且它有效。这是有效的代码片段:

resource "local_file" "literature" {
 filename = "art_of_war.txt"
 content = <<EOT
  Hello
  World
EOT
}
Run Code Online (Sandbox Code Playgroud)

请注意,EOT左对齐到与 相同的水平resource

编辑:实际上,似乎在 后面有一个空格<<EOT,如果你删除它它应该可以工作。

  • “额外的空间”对我来说就是一切,谢谢 Marko E! (7认同)