-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
remote-exec
does not work with ssh connection to ec2 Windows Server 2019
#25634
Comments
Thanks for reporting this issue! I'm not sure what could be causing this problem. Could you try running |
Here are some of the logs. Looks like something is getting very messed up with the command passed to
|
Thanks! I was able to reproduce this issue with the steps below:
Using Remote Desktop to connect to the instance, I can see that there's an empty file at |
I tried updating the script path in the connection block: connection {
type = "ssh"
host = coalesce(self.public_ip, self.private_ip)
user = "Administrator"
password = rsadecrypt(self.password_data, file("${path.module}/id_rsa"))
script_path = "/Windows/Temp/terraform_%RAND%.bat"
} This leads to a new and more difficult to fix error, which is that remote-exec inline scripts are uploaded with a shebang line: terraform/communicator/ssh/communicator.go Lines 28 to 31 in a119ac1
This results in a new error which can't be fixed with configuration:
The underlying issue here is that Terraform expects an SSH connection to result in a UNIX-like environment, whereas the OpenSSH server on Windows 10 results in a cmd.exe shell instead. I think to address this, we would need to at least allow the shebang prefix to be disabled for inline scripts. As an alternative, we might be able to alter the remote-exec provisioner to execute single commands directly rather than generating a shell script and using scp to upload it. |
Ah! One final update: despite the shebang-induced error, the rest of the batch script actually does execute. While there's some ugly and confusing output from the SSH implementation, I think this might mean that you actually can use remote-exec with OpenSSH on Windows 10, so long as you set a If you could confirm the workaround is effective for you, that would be helpful! |
@alisdair Awesome! The work around worked thanks! I appreciate your time. |
I've run into this over on the Nomad team (ref hashicorp/nomad#8748) and having trouble with this workaround. (Unfortunately because we need to be able to push custom binaries from the tester's workstation, we execute this provisioning via userdata.) locals {
# workaround for https://github.com/hashicorp/terraform/issues/25634
script_path = var.platform == "windows_amd64" ? "C:/Windows/Temp/terraform_%RAND%.bat" : ""
}
resource "null_resource" "provision_nomad" {
connection {
type = "ssh"
user = var.connection.user
host = var.connection.host
port = var.connection.port
private_key = var.connection.private_key
timeout = "15m"
script_path = local.script_path
}
provisioner "remote-exec" {
inline = [
# this is actually templated, but I've verified the arguments themselves are ok
"C:\opt\provision.ps1 -nomad_version 0.12.3"
]
}
} The symptoms are as described above: the
Running the script directly via ssh (ex. |
EDIT: opened PR #26865 which contains a fix |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Terraform Version
Terraform Configuration Files
Expected Behavior
There should be a
test.txt
file on the ec2 instance. Theremote-exec
commands do not seem to be executed at all.Actual Behavior
There is no
test.txt
file on the ec2 instance.Steps to Reproduce
terraform init
terraform apply
Additional Context
References
The text was updated successfully, but these errors were encountered: