tfutils / tfenv

Terraform version manager
MIT License
4.52k stars 454 forks source link

Status of Git Bash on Windows support (users: do not set MSYS_NO_PATHCONV) #379

Open mloskot opened 1 year ago

mloskot commented 1 year ago

Currently, the README.md states

Windows (64bit) - only tested in git-bash - currently presumed failing due to symlink issues in git-bash

Are there any details in the "failing due to symlink issues", what was/is the actual problem?

I have not noticed any problems using tfenv with Git Bash from git version 2.39.2.windows.1 on Windows 11, with

$ git config --show-origin --get-all core.symlinks
file:C:/Program Files/Git/etc/gitconfig false
file:C:/Users/mateuszl/.gitconfig       true

So, I'm wondering if this warning in the README still holds. Perhaps it should be removed.

mloskot commented 1 year ago

After upgrading to later Git git version 2.40.0.windows.1, I'm observing a strange issue on Windows 11 in Git Bash using tfenv 3.0.0

$ tfenv install 1.3.9
Installing Terraform v1.3.9
Downloading release tarball from https://releases.hashicorp.com/terraform/1.3.9/terraform_1.3.9_windows_amd64.zip
Warning: Failed to open the file
Warning: /tmp/tfenv_download.KCNLaP/terraform_1.3.9_windows_amd64.zip: No such
Warning: file or directory
curl: (23) Failure writing output to destination

Tarball download failed

It looks like /tmp/tfenv_download.KCNLaP could not be even created.

mloskot commented 1 year ago

Ha! I found what caused the problem 0 it was not upgrade to Git 2.40, but change in my environment:

$ env |grep MSYS_
MSYS_NO_PATHCONV=1

and as soon as I did unset MSYS_NO_PATHCONV, everything worked fine:

$ tfenv install 1.3.9
Installing Terraform v1.3.9
Downloading release tarball from https://releases.hashicorp.com/terraform/1.3.9/terraform_1.3.9_windows_amd64.zip
###################################################################################################################################################################################################################################### 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.3.9/terraform_1.3.9_SHA256SUMS
Not instructed to use Local PGP (/c/Users/mateuszl/.tfenv/use-{gpgv,gnupg}) & No keybase install found, skipping OpenPGP signature verification
Archive:  /tmp/tfenv_download.XlD5a4/terraform_1.3.9_windows_amd64.zip
  inflating: /c/Users/mateuszl/.tfenv/versions/1.3.9/terraform.exe
Installation of terraform v1.3.9 successful. To make this your default version, run 'tfenv use 1.3.9'
$ tfenv use 1.3.9
Switching default version to v1.3.9
Default version (when not overridden by .terraform-version or TFENV_TERRAFORM_VERSION) is now: 1.3.9
$ terraform version
Terraform v1.3.9
on windows_amd64
kesavab commented 1 year ago

I am facing an issue with git bash +tfenv +make. Issue is, I am using tfenv to set terraform version. I set to 1.5 on my git bash terminal. When I run the make command that calls terraform, there the terraform version is different and its like 0.12.x. The make's sub shell is not getting the terraform version set by tfenv from the parent shell.

image

c33s commented 1 year ago

Windows (64bit) - only tested in git-bash - currently presumed failing due to symlink issues in git-bash i don't know where the symlinks are used exactly, so the suggestion might be wrong:

on windows real symlinks are a real pain as you have to change a policy to be able to create a symlink or you have to work in an elevated shell. a trap is that if the user is an admin, even when setting the policy the creation of symlinks does not work. if your user can summon an elevated shell then it is not possible to create a symlink even if the policy is set (found this info after some googling on stackoverflow).

so my suggestion is, just use junctions on windows if you only want to link between directories. as far as i remember composer (php) has such a feature. simply falling back to junctions on windows. requires no policy change and no admin user.

i build myself a pvm (php version manager) which switches between multiple php versions without any problems with junctions.