Skip to content
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

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

Closed
stevehipwell opened this issue Oct 15, 2021 · 12 comments · Fixed by #327
Closed

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

stevehipwell opened this issue Oct 15, 2021 · 12 comments · Fixed by #327

Comments

@stevehipwell
Copy link

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.

@warrensbox
Copy link
Owner

I'll work on this.

@stevehipwell
Copy link
Author

@warrensbox have you made any progress with this?

@siran
Copy link

siran commented Jul 14, 2022

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

@ziggy471
Copy link

ziggy471 commented Jul 19, 2022

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.

@yermulnik
Copy link
Collaborator

@ziggy471 Would you mind contributing by opening a PR for these changes?
https://github.com/warrensbox/terraform-switcher#how-to-contributehttps://tfswitch.warrensbox.com/How-to-Contribute/
Thank you.

@ziggy471 ziggy471 mentioned this issue Jul 19, 2022
@ziggy471
Copy link

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.

@mhnaufal
Copy link

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

@ziggy471
Copy link

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.

@fsdrw08
Copy link

fsdrw08 commented Apr 25, 2023

any update of this issue?

@tomer-ds
Copy link

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

@kdpuvvadi
Copy link

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

@systematicguy
Copy link

FYI I confirm this works now properly on windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants