Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support heredoc without interpolation #207

Closed
arnd opened this issue Aug 6, 2017 · 1 comment
Closed

Support heredoc without interpolation #207

arnd opened this issue Aug 6, 2017 · 1 comment

Comments

@arnd
Copy link

arnd commented Aug 6, 2017

It would be great if herdoc syntax for strings would allow for heredocs without interpolation (e.g. like in Bash).

HCL Template

resource "google_compute_instance" "demo" {
  name         = "demo0"
  machine_type = "f1-micro"
  zone         = "europe-west1-b"

  metadata_startup_script = <<'EOT'
echo '${'
EOT

}

Expected behavior

I would have expected, that the string gets assigned without interpolation.

Actual behavior

What actually happened?
An error is thrown, because of the quotes around EOT.

arnd@machine:~/demo$ terraform plan
Failed to load root config module: Error parsing /home/arnd/demo/demo.tf: At 6:35: illegal char

However, obviously without the quotes, the hcl parser will choke on the string because it tries to interpolate ${.

Steps to reproduce

  1. Use terraform plan on above template.
@apparentlymart
Copy link
Contributor

Hi @arnd! Thanks for this suggestion.

I understand the benefits of such a syntax; it can be frustrating to need to escape everything when using a nested language that also uses ${ as significant punctuation.

There is a tension here with the complexity of the language; there are already several different string variants in HCL, with subtle differences between them, and so I'm somewhat reticent to add another. I'm also a little concerned about activating such a mode using such a subtle syntax, since it is unlikely to be obvious to all readers that placing the identifier in quotes activates a new behavior. I understand that this is familiar to those with more advanced knowledge of shell languages, but HCL tries to be more explicit to ease understanding of configuration by newcomers.

For Terraform in particular, our recommendation would be to factor out such scripts into a separate file and include it using the file function, which interprets the file contents literally rather than processing interpolations. This is often easier to maintain for non-trivial scripts anyway, since e.g. a text editor can use its highlighting and tooling for the shell syntax rather than just seeing it as a nested string literal.

This doesn't generalize to other applications that use HCL of course, but it seems like you are primarily motivated by a Terraform-specific use-case here. Given that Terraform has the file function as a means to achieve this result, at this time I'm going to recommend making use of that to avoid the additional complexity of adding a new string parsing mode.

Thanks again for suggesting this; I understand that the file solution is not ideal for all cases, but I lean towards keeping the main language simpler since that hopefully makes it easier to learn. With that said, I'm going to close this, though I certainly will keep this use-case in mind in case we find other opportunities to address the original concern in a different way. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants