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

fix(terraform.go): remove trailing newline from output value #50

Merged
merged 4 commits into from
Aug 24, 2020

Conversation

vdice
Copy link
Member

@vdice vdice commented Aug 20, 2020

  • Removes the trailing newline from the output value returned from terraform output <output name> prior to bubbling up

Fixes #20

Note: Although the --json format flag on terraform output looks handy (as noted in #20 (comment)) it appears the terraform CLI appends the newline character in this case as well -- and we'd have the extra task of removing the wrapping double quotes. Hence, I went the simpler route and stuck with the default format.

Signed-off-by: Vaughn Dice <vadice@microsoft.com>
Co-authored-by: Carolyn Van Slyck <me@carolynvanslyck.com>
Signed-off-by: Vaughn Dice <vadice@microsoft.com>
Signed-off-by: Vaughn Dice <vadice@microsoft.com>
@vdice
Copy link
Member Author

vdice commented Aug 24, 2020

@carolynvs I added a check to the current cli tests but have also created an issue around your suggestion to look into possibilities for unit test coverage in the future: #51

exit 1
fi

# Verify the output has no extra newline (mixin should trim newline added by terraform cli)
Copy link
Member

Choose a reason for hiding this comment

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

Is the extra check here necessary now that we are doing the exact equality check above? If there was a newline, wouldn't the != "bar" catch it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great question. Alas, bash's default command substitution strips trailing newline characters. I've been looking into ways to work around this (https://stackoverflow.com/questions/15184358/how-to-avoid-bash-command-substitution-to-remove-the-newline-character has been particularly helpful), but they seem to quickly grow ungainly. I also see that I should create a function to validate a given output, as we do so after install as well; so I'll at least update to DRY that up...

Signed-off-by: Vaughn Dice <vadice@microsoft.com>
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@vdice vdice merged commit f9d2615 into getporter:main Aug 24, 2020
@vdice vdice deleted the fix/rm-output-newline branch August 24, 2020 21:33
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.

Whitespace on outputs?
2 participants