-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Comments
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. 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. |
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. |
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. |
Thanks, HCL is the right place for this. |
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. |
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:
Resultant plan output (notice the newlines):
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:
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
The text was updated successfully, but these errors were encountered: