hashicorp-community / tf-helper

Commands for performing operations on Terraform states, configurations, TFE using the API, and more. Please target all PRs to the master branch, not the release branch.
Mozilla Public License 2.0
102 stars 32 forks source link

error awk: newline in string #1

Closed brianabston001 closed 5 years ago

brianabston001 commented 5 years ago

When trying to run tfh help it will display the first time. Then after that it gives the following:

awk: newline in string /Users/USERNAME/git/t... at source line 1
awk: newline in string /Users/USERNAME/git/t... at source line 1
awk: newline in string /Users/USERNAME/git/t... at source line 1

If I try tfh cache -clear I get the same error. If I delete the cache folder I am able to run help again and it works but then the error comes back.

Pretty much anything tfh I get the three lines above. Am I doing something wrong?

fprimex commented 5 years ago

Found and fixed this bug this morning. Please pull the release branch and see if it resolves the issue. Thanks!

brianabston001 commented 5 years ago

updated the release branch and see the changes but still get them same errors as above. I deleted the cache again and was able to run help one time and it has those errors and then the following time help will not run. Also tried to run the tfh curl-config -tfrc and get the same thing

fprimex commented 5 years ago

Figured this out. I had tested with busybox's awk, so I thought I had MacOS's One True AWK version covered. I had been using gawk, myself. Turns out that this is not sufficient, as busybox's version must have some fixes and enhancements beyond the One True AWK version shipped with MacOS.

The limitation is that awk on mac can't take a multiline string as a variable using, -v like

$ shell_var="line 1
line 2"

$ awk -v sv="$shell_var" 'BEGIN {print sv}'
awk: newline in string line 1
line 2... at source line 1

The workaround is to send it as an arg and process it out of ARGV.

$ awk 'BEGIN {sv=ARGV[1]; delete ARGV[1]; print sv}' "$shell_var"
line 1
line 2

Release 0.2.3 should have this covered. I'll make sure not to rely on busybox's awk as a substitute for testing the one on MacOS.

Along the way I fixed some other things of course. Cheers!