terraform-switcher icon indicating copy to clipboard operation
terraform-switcher copied to clipboard

This doesn't work on Windows despite there being a binary

Open stevehipwell opened this issue 4 years ago • 8 comments

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.

stevehipwell avatar Oct 15 '21 08:10 stevehipwell

I'll work on this.

warrensbox avatar Jan 24 '22 17:01 warrensbox

@warrensbox have you made any progress with this?

stevehipwell avatar Mar 07 '22 08:03 stevehipwell

is there going to be a Windows version? are there any blockers to doing having one?

siran avatar Jul 14 '22 19:07 siran

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 avatar Jul 19 '22 18:07 ziggy471

@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.

yermulnik avatar Jul 19 '22 20:07 yermulnik

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.

ziggy471 avatar Jul 19 '22 20:07 ziggy471

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

mhnaufal avatar Jul 26 '22 02:07 mhnaufal

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.

ziggy471 avatar Jul 26 '22 14:07 ziggy471

any update of this issue?

fsdrw08 avatar Apr 25 '23 07:04 fsdrw08

Huge time +1!!!! Pretty disappointed... but will have to continue to use choco install -y terraform -version=<version> to overwrite current installation....

tomer-ds avatar Jun 22 '23 06:06 tomer-ds

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

kdpuvvadi avatar Oct 12 '23 08:10 kdpuvvadi

FYI I confirm this works now properly on windows.

systematicguy avatar Apr 29 '24 15:04 systematicguy