-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Loading modules via Git, terraform ignores GIT_SSH environment variable #19232
Comments
After doing some further inspection in the terraform source code I understand, that the environment variable |
Hi @standardizer, you've got it correct in your second comment. The Thanks! |
Hi @mildwonkey, you’re assuming the Git client is responsible for handling |
Hmm, thank you for the information @standardizer - I'll re-open this and label it appropriately so we can take a look. (If you are interested in contributing to terraform, a PR would also be welcome!) |
I think I remember encountering this before, and finding that Terraform was handling the environment variable itself here because it wanted to impose its own special default handling in the case where the variables aren't set. I think it was to handle a situation related to running Git on Windows. I don't remember exactly where this code is, but treating |
I'm having a similar issue, I've set I've also set my global git config to do the same with But |
I was able to get this working by escaping the |
I don't think that treating GIT_SSH & GIT_SSH_COMMAND as synonyms is sufficient to fix this problem. Terraform shouldn't be overriding the configured git behavior at all. Since it appears to be checking an environment variable directly and trying to override normal git behavior regarding SSH when it sees that it isn't set, the core.sshCommand key, which can be set in a user's .gitconfig or in the system git config, is also ignored. I worked around this by setting GIT_SSH_COMMAND in the environment, but it certainly came as a surprise to me when git clone of my modules repository worked just fine from the command line but git run via Terraform reports that I have a pubkey with an invalid format (in fact, it appears to be trying to read my private key for some reason). |
Additionally; if the path to plink has a space in it, this won't work. |
Just encountered that issue, which I worked around by setting Additionally, while researching this error, I've found several issues (such as this one) that were opened with similar errors, which were caused by an ambiguity in parsing module source between "SCP style" and "URL style". While that bug has been fixed in the current version of Terraform, because the symptom is the same as for the bug described here (failure to clone a module from Git via SSH), it made it challenging to find this workaround. |
I'm pretty sure this is because when Terraform runs a What happens when you set GIT_SSH_COMMAND as people have suggested here is that you are telling Git for Windows to use the OpenSSH-Win32 client that is installed in Windows recent versions (hence the C:\Windows\System32\OpenSSH\ssh.exe path) and it works because it is compiled to work with Windows - internally it uses Windows paths rather than Unix paths, and it has a Windows service implementation of ssh-agent for storing the identity after prompting for a private key passphrase. Some have said that GIT_SSH_COMMAND doesn't work if there is a space in the path - it does work, but I think that if you've tried it with a path with a space you've probably tried to set the path to point to C:\Program Files\Git\usr\bin\ssh.exe - but that is the SSH client installed with Git for Windows, which as I've explained doesn't work with Terraform. Here's what I do in Windows, works well for me:
You may need to close all Visual Studio Code open windows after setting the environment variable as Visual Studio Code sometimes does not see new environment variables even after opening a new Terminal. Full instructions for installing OpenSSH-Win32 are here: https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH More info here too: https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement |
Yes, that will work for the same reason as OpenSSH-Win32 ssh.exe, ie. you're doing what I described above but using PuTTY plink.exe instead of the OpenSSH-Win32 ssh.exe that I'm using. As you've seen the space in the path works fine for plink.exe too because the space is not the issue that people are seeing, the issue is caused by using the CygWin version of ssh.exe. |
What I wanted to highlight was the fact that I had to explicitly add the double quotes in the variable value, Without the quotes it didn't work for me. |
I want to apologize for the slow response time on this issue, and also let you know that I am bulk-closing all issues exclusively reported against Terraform 0.11.x, including this issue, because we are no longer investigating issues reported against Terraform 0.11.x. In most cases, when we try to reproduce issues reported against 0.11, we either can't reproduce them anymore, or the reporter has moved on, so we believe we can better support the Terraform user community by prioritizing more recent issues. Terraform 0.12 has been available since May of 2019, and there are really significant benefits to adopting it. I know that migrating from 0.11 to versions past 0.12 can require a bit of effort, but it really is worth it, and the upgrade path is pretty well understood in the community by now. 0.14 is available and stable, and we are quickly approaching an 0.15 release. We have made a significant effort in the last year to stay on top of bug reports; we have triaged almost all new bug reports within 1-2 weeks for 6+ months now. If you are still experiencing this problem, please submit a new bug report with a reproduction case that works on 0.14.x, link this old issue for context, and we will triage it. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Terraform Version
Terraform Configuration Files
Expected Behavior
Running
terraform init
, which ist loading the modulemymodule.git
using git internally, the executableplink.exe
should be used, likegit clone
does it right here: https://gist.github.com/standardizer/da751da4c325af97ca9a18247dd2e53dThe SSH key is delivered by Pageant (part of PuTTY), which is called by plink.exe.
Actual Behavior
Running
terraform init
, which ist loading the modulemymodule.git
using git internally, the executablessh
is used: https://gist.github.com/standardizer/09fda4ca1e246e4e43868e84ce7a6c30The module cannot be cloned, because
ssh
is not prepared to use the SSH key, as it should not be called at all.Steps to Reproduce
terraform init
Additional Context
Windows 10 Pro x64 Version 18.03
Environment variables set:
SET GIT_SSH=C:\Program Files\PuTTY\plink.exe
Git configuration (additionally set, but not needed for
git clone
working properly):git config --global ssh.variant plink
References
The text was updated successfully, but these errors were encountered: