Loading...
Loading...
Terraform's `remote-exec` with `type=ssh` won't connect to remote Windows boxes when the default shell is `powershell.exe` 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`. ### Terraform Version <!--- Run `terraform version` to show the version, and paste the result between the ``` marks below. If you are not running the latest version of Terraform, please try upgrading because your issue may have already been fixed. --> ``` Terraform v1.3.0-dev ``` ### Terraform Configuration Files <!-- Paste the relevant parts of your Terraform configuration between the ``` marks below. For Terraform configs larger than a few resources, or that involve multiple files, please make a GitHub repository that we can clone, rather than copy-pasting multiple files in here. For security, you can also encrypt the files using our GPG public key at https://www.hashicorp.com/security. --> ```terraform resource "null_resource" "web" { connection { type = "ssh" user = var.admin_username password = var.admin_password host = azurerm_windows_virtual_machine.vm.public_ip_address target_platform = "windows" script_path = "c:/windows/temp/terraform_%RAND%.ps1" } provisioner "remote-exec" { inline = [ "echo hello" ] } } ``` ### Debug Output <!-- Full debug output can be obtained by running Terraform with the environment variable `TF_LOG=trace`. Please create a GitHub Gist containing the debug output. Please do _not_ paste the debug output in the issue, since debug output is long. Debug output may contain sensitive information. Please review it before posting publicly, and if you are concerned feel free to encrypt the files using the HashiCorp security public key. --> ### Expected Behavior The remote should respond with `hello` ### Actual Behavior Logs: ```text module.sqlvm001.null_resource.web: Provisioning with 'remote-exec'... module.sqlvm001.null_resource.web (remote-exec): Connecting to remote host via SSH... module.sqlvm001.null_resource.web (remote-exec): Host: 20.234.17.144 module.sqlvm001.null_resource.web (remote-exec): User: foods module.sqlvm001.null_resource.web (remote-exec): Password: true module.sqlvm001.null_resource.web (remote-exec): Private key: false module.sqlvm001.null_resource.web (remote-exec): Certificate: false module.sqlvm001.null_resource.web (remote-exec): SSH Agent: false module.sqlvm001.null_resource.web (remote-exec): Checking Host Key: false module.sqlvm001.null_resource.web (remote-exec): Target Platform: windows 2022-07-12T11:51:52.262+0100 [DEBUG] Connecting to 20.234.17.144:22 for SSH 2022-07-12T11:51:52.274+0100 [DEBUG] Connection established. Handshaking for user foods module.sqlvm001.null_resource.web (remote-exec): Connected! 2022-07-12T11:51:52.623+0100 [DEBUG] starting ssh KeepAlives 2022-07-12T11:51:52.625+0100 [DEBUG] opening new ssh session 2022-07-12T11:51:52.714+0100 [DEBUG] Starting remote scp process: "scp" -vt c:/windows/temp 2022-07-12T11:51:52.732+0100 [DEBUG] Started SCP session, beginning transfers... 2022-07-12T11:51:52.735+0100 [DEBUG] Beginning file upload... 2022-07-12T11:51:52.905+0100 [DEBUG] SCP session complete, closing stdin pipe. 2022-07-12T11:51:52.908+0100 [DEBUG] Waiting for SSH session to complete. 2022-07-12T11:51:52.914+0100 [ERROR] scp stderr: "At line:1 char:7\r\n+ \"scp\" -vt c:/windows/temp\r\n+ ~~~\r\nUnexpected token '-vt' in expression or statement.\r\nAt line:1 char:11\r\n+ \"scp\" -vt c:/windows/temp\r\n+ ~~~~~~~~~~~~~~~\r\nUnexpected token 'c:/windows/temp' in expression or statement.\r\n + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException\r\n + FullyQualifiedErrorId : UnexpectedToken\r\n \r\n" 2022-07-12T11:51:52.915+0100 [ERROR] Process exited with status 1 ``` ### Steps to Reproduce 1. Configure a Windows instance with OpenSSH and set the default shell to PowerShell (PS1) 2. Run the example above ### Additional Context If the `script_path` directive is omitted the behaviour is the same. ### References * Implemented in #26865 see section `PS1 Configuration` * PS1 stopped working due to #28626
Click on a version to see all relevant bugs
Terraform Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.