terraform
terraform copied to clipboard
Generate a working ps1 command from remote-exec ssh
Terraform's remote-exec with type=ssh
won't connect to remote Windows boxes due to quoted escaping on the scp command passed to the ssh layer.
The Windows command "scp" -vt c:/windows/temp
is passed to the remote which works fine where the shell is cmd.exe
but fails when the shell is powershell.exe
.
Raised as issue #31423.
Thanks for this submission. Although I cannot commit to having this PR reviewed at this time, we acknowledge your contribution and appreciate it! Thanks again for the submission!
I just saw comment https://github.com/hashicorp/terraform/issues/31423#issuecomment-1181822679! Apologies if my previous message was confusing.
@crw no worries, I've got a local build with this change and will be running it as part of my IaC workflow until/if the PR is merged
does noone manage issues/PRs at hashicorp. how long do things have to lie in wait when the community contributes?
@rismoney We do look at them. Unfortunately Provisioners are in a bit of a stasis, in general we are not trying to add more features to them although we do occasionally accept bugfix contributions. This PR is the victim of its specific use case, we'd need someone internally with Powershell to test - not impossible, but it has not been a top priority for a variety of reasons. For more on Provisioners generally see: https://github.com/hashicorp/terraform/blob/main/.github/CONTRIBUTING.md#provisioners
Thanks for your comment!
@craigminihan Please see the above comments from @alisdair.
@crw @alisdair I can create some HCL to provision a Windows box with OpenSSH + cmd and another with OpenSSH + PowerShell and test code to exercise this change.
TBH the quote change made previously (go-shquot) broke the PowerShell handling of the script command. "/script/hello-world.ps1"
is a string whereas /script/hello-world.ps1
is an executable command to the PowerShell command interpreter.
Prefixing the string with a &
turns it back into a command again, for example &"/script/hello-world.ps1"
would be executed.
Sample configs for manual testing would be great, thanks!
TBH the quote change made previously (go-shquot) broke the PowerShell handling of the script command.
I understand that. What I'm suggesting is that we should try to make use of the ViaPowerShell
function in go-shquot
to implement the correct command quoting, instead of prepending an ampersand inline.
If you're revisiting this, I think it's worth considering my other question from the prior review, too:
Do we need a way for users to specify that the target platform is Windows+Powershell?