terraform-switcher
terraform-switcher copied to clipboard
This doesn't work on Windows despite there being a binary
I downloaded your latest version onto Windows and when I tried to use it I got the following error.
PS ~> tfswitch --latest-stable 1.0 [Error] : Binary path does not exist: \usr\local\bin [Error] : Manually create bin directory at: \usr\local\bin and try again.
I'm happy to help you figure out the Windows version of this, nvs solves this problem in the same space.
Once this is working in Windows I'll re-open my PR to add tfswitch to scoop and open a PR back here for the docs.
I'll work on this.
@warrensbox have you made any progress with this?
is there going to be a Windows version? are there any blockers to doing having one?
Should be just a 1 line change in lib/install.go:
- binPath = InstallableBinLocation(binPath)
+ binPath = ConvertExecutableExt(InstallableBinLocation(binPath))
Then to build: GOOS=windows GOARCH=amd64 go build -o tfswitch.exe
Arrow keys won't work, it's an issue with promptui, so when selecting in the list you can use j and k.
@ziggy471 Would you mind contributing by opening a PR for these changes? https://github.com/warrensbox/terraform-switcher#how-to-contribute → https://tfswitch.warrensbox.com/How-to-Contribute/ Thank you.
Finally had time to figure out the arrow keys as well. Actually had to figure out the windows binpath about 6 months ago when we started having some guys use windows. Just figured someone else would find a better fix prior to me remembering to actually do a PR for it.
Hi!
I found a workaround for this. Instead of running the normal tfswitch command, I use the -b flag to specify where I want to install my selected Terraform version (although from what I try, it doesn't have any effect): tfswitch -b C:\Users\MyUser\Desktop. Then it will download the Terraform into the C:\Users\MyUser\.terraform.version.
After that, tfswitch will try to create a symlink to the downloaded path and add it to the ENV variables, but it failed. So as a workaround I add the C:\Users\MyUser\.terraform.version path to my ENV variables and rename the downloaded Terraform inside it to a new name (e.g. terraform2). And when I run terraform2 version, it works (hopefully).
Hope that's help
The fix was a minimal fix to get the correct extension and working arrow keys, for my guys on Windows I've suggested the following in their PS Profile, 7.2 required:
$env:Path = "~\bin;$env:Path"
function cdtf {
param($path)
if (!$path) {
$path = $HOME
}
set-location $path
if ((Test-Path $PWD\.tfswitch.toml) -Or (findstr.exe /IC:required_version $PWD\*.tf 2>nul)) {
tfswitch
}
}
function tfswitch {
~/bin/tfswitch.exe -b $HOME/bin/ $Args
}
New-Alias tf terraform
Remove-Item alias:\cd
New-Alias cd cdtf
This allow for PS to check when you change directories if it needs to switch, you could remove the check and just run tfswitch with every cd as well.
any update of this issue?
Huge time +1!!!!
Pretty disappointed... but will have to continue to use choco install -y terraform -version=<version> to overwrite current installation....
Huge time +1!!!! Pretty disappointed... but will have to continue to use
choco install -y terraform -version=<version>to overwrite current installation....
or winget install --id Hashicorp.Terraform --version 1.6.0
FYI I confirm this works now properly on windows.