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

Escape shell vars in HCL output #28

Merged
merged 1 commit into from
Aug 30, 2021
Merged

Escape shell vars in HCL output #28

merged 1 commit into from
Aug 30, 2021

Conversation

jrhouston
Copy link
Owner

@jrhouston jrhouston commented Aug 28, 2021

Closes #27

@@ -88,6 +88,12 @@ func snakify(s string) string {
return strings.ToLower(re.ReplaceAllString(s, "_"))
}

// escape incidences of ${} with $${} to prevent Terraform trying to interpolate them
func escapeShellVars(s string) string {
r := regexp.MustCompile(`(\${.*?})`)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .*? here is to make the regexp not greedy – otherwise it would match ${VAR1} ${VAR2} as one group.

// escape incidences of ${} with $${} to prevent Terraform trying to interpolate them
func escapeShellVars(s string) string {
r := regexp.MustCompile(`(\${.*?})`)
return r.ReplaceAllString(s, `$$$1`)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is three $ because $1 uses the first group, then we need to escape the $ we want to put in front of it 😅

@jrhouston
Copy link
Owner Author

@curtbushko if you want to try this for your use case and make sure it works.

@jrhouston
Copy link
Owner Author

Just tried the with the manifest mentioned in the issue and it validates successfully.

@jrhouston jrhouston merged commit 1e9bd4b into main Aug 30, 2021
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

Successfully merging this pull request may close these issues.

Escape shell variables (${...}) in text fields so Terraform doesn't try to interpolate them
1 participant