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

Feature request: multi-line strings for resource argument values #8210

Closed
adampats opened this issue Aug 16, 2016 · 5 comments
Closed

Feature request: multi-line strings for resource argument values #8210

adampats opened this issue Aug 16, 2016 · 5 comments

Comments

@adampats
Copy link

adampats commented Aug 16, 2016

Hello,

Considering that resource argument value strings can get quite long column-wise, I thought I'd propose an additional formatting option to spread a string across multiple lines that would potentially escape white-space and / or newlines. The currently supported HEREDOC style option is great for capturing a raw block of text with all the formatting, but this is not very useful for doing regular strings within a resource for the purposes of keeping the code clean / readable.

Example:

tags {
  Name = <<EOF
${var.global["product"]}-${var.global["project"]}-
app-web-inbound-elb-${var.global["environment"]}
EOF
}

Resultant plan output (notice the newlines):

tags.Name:                              "product-project-\napp-web-inbound-elb-dev\n"

I would think using a mechanism available in many other languages would be more appropriate for this use-case, i.e. something similar to Groovy's triple quote:

tags {
  Name = """
    ${var.global["product"]}-${var.global["project"]}-\
    app-web-inbound-elb-${var.global["environment"]}
  """
}

Although, this example is quite trivial, some fancier strings that include multiple interpolations, etc can get extremely long and even with editor word wrap are still quite ugly / difficult to read. Thoughts?

Terraform Version

Terraform v0.7.0

References

HCL HEREDOC support: hashicorp/hcl#34

@apparentlymart
Copy link
Contributor

Hi @adampats!

I'm not familiar with Groovy, so would you mind helping me understand the specific behavior you're looking for here?

From that example, it seems like what you want is a kind of multi-line string literal where leading and trailing space characters, along with the newlines themselves, are stripped from the string. Is that right? That does sound useful, if so!

From a UX perspective we should probably treat carefully with what specific punctuation we choose here. """ means different things in different languages (e.g. in Python it encloses something behaving a lot like a heredoc in Terraform) and so it might create a "false cognate" that causes some users to misunderstand what it does, since Terraform users are coming from many different programming language communities.

I feel kinda tempted to just make HCL support multi-line single-quoted strings, with it removing all newlines and the spaces around them as (I think) you suggest. This way it will hopefully look sufficiently different to both Groovy and Python that no-one will be confused by the similarity, and shouldn't be a compatibility constraint since multi-line strings are not allowed in HCL today.

@apparentlymart
Copy link
Contributor

Thinking a bit more here, I think whatever we would do to address this issue would actually be an HCL change rather than a Terraform change, so maybe we should move this issue over there so it's more visible to all of the folks working on the different projects that use HCL.

@adampats
Copy link
Author

Yes, you interpreted my intended functionality correctly - a multi-line string literal with all the white-space and newlines removed (or at least escaped). I also agree about the single-quote syntax to avoid confusion.

Another option would be to break it up using string concatenation operators and a new-line escape, similar to (how I do it) in Python:

tags {
  Name = "${var.foo}-${var.bar}-" + \
    "my-application-elb-${var.baz}"
}

I'll open an issue under HCL.

@mitchellh
Copy link
Contributor

Thanks, HCL is the right place for this.

@ghost
Copy link

ghost commented Apr 23, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants