fix(hcl2cdk): Handle multi-line strings better #2812
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issue
Fixes https://github.com/orgs/hashicorp/projects/207/views/12?pane=issue&itemId=25824022
Description
This is a pretty hacky PR, and I'm not really comfortable with the solution. That being said, I think this does resolve our immediate woes around heredocs.
The problem is as such: By the time the heredoc string comes in for parsing by the expression parser, (I suspect) the hcl2json parser has already converted it into a quote containing newlines. Quote with newlines are not accepted within HCL and thus breaks our expression.
This PR tries to detect newlines within string literals and wraps them back into a heredoc literal, making the expression parseable. As you can see from the PRs, this requires a lot of tweaks to existing logic to ensure it works ok, and even then, I'm not 100% sure this will not be caught off guard on other situations.
Checklist