hashicorp / terraform-google-vault

A Terraform Module for how to run Vault on Google Cloud using Terraform and Packer
Apache License 2.0
113 stars 75 forks source link

Permission denied (publickey). fatal: Could not read from remote repository. #45

Open akamalov opened 5 years ago

akamalov commented 5 years ago

Environment Terraform: 0.12.3

Problem

Trying to initialize terraform with terraform-google-consul module version of 0.4.0 - https://github.com/hashicorp/terraform-google-consul/releases/tag/v0.4.0

Getting an error on terraform init:

Initializing modules...
Downloading git::git@github.com:hashicorp/terraform-google-consul.git?ref=v0.4.0 for consul_cluster...

Error: Failed to download module

Could not download module "consul_cluster" (main.tf:118) source code from
"git::git@github.com:hashicorp/terraform-google-consul.git?ref=v0.4.0": error
downloading
'ssh://git@github.com/hashicorp/terraform-google-consul.git?ref=v0.4.0':
/usr/local/bin/git exited with 128: Cloning into
'.terraform/modules/consul_cluster'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Error: Failed to download module

Could not download module "consul_cluster" (main.tf:118) source code from
"git::git@github.com:hashicorp/terraform-google-consul.git?ref=v0.4.0": error
downloading
'ssh://git@github.com/hashicorp/terraform-google-consul.git?ref=v0.4.0':
/usr/local/bin/git exited with 128: Cloning into
'.terraform/modules/consul_cluster'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Error: Failed to download module

Could not download module "consul_cluster" (main.tf:118) source code from
"git::git@github.com:hashicorp/terraform-google-consul.git?ref=v0.4.0": error
downloading
'ssh://git@github.com/hashicorp/terraform-google-consul.git?ref=v0.4.0':
/usr/local/bin/git exited with 128: Cloning into
'.terraform/modules/consul_cluster'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Here is the snippet of my main.tf file referencing a module:

# ---------------------------------------------------------------------------------------------------------------------
# DEPLOY THE CONSUL SERVER CLUSTER
# Note that we make use of the terraform-google-consul module!
# ---------------------------------------------------------------------------------------------------------------------

module "consul_cluster" {
  source = "git::git@github.com:hashicorp/terraform-google-consul.git//modules/consul-cluster?ref=v0.4.0"
  #source = "git::git@github.com:hashicorp/terraform-google-consul.git//modules/consul-cluster?ref=v0.2.1"

  subnetwork_name = "${google_compute_subnetwork.private_subnet_with_google_api_access.name}"

Not sure what's going on here..

Etiene commented 5 years ago

Weird! Try again once this PR is merged though #44 and then we will have a look

KZachariassen commented 5 years ago

Hi, We are seeing the same thing using terraform v0.12.6.

We are using terraform on windows and we are getting this error if we use SSH, when we change the source to use HTTPS it works.

This does not work

module "test" {
  source = "git::ssh://github.test.io/test/test.git"
}

This works

module "test" {
  source = "git::https://github.test.io/test/test.git"
}

Using git command manually works perfectly. I was suspecting this to be a windows-only problem?

nhart-alf commented 5 years ago

Hi,

Having the same issue here. Terraform 0.12.8. Windows 10 1903.

HTTPS works: module "tags" { source = "git::https://git@github.com/CompanyName/blah-terraform-modules.git//tags?ref=develop"

SSH fails: module "tags" { source = "git@github.com:CompanyName/blah-terraform-modules.git//tags?ref=develop"

Git works standalone to drag these items over ssh using my ssh key that is set systemwide. Github Desktop also works for ssh using that same key.

I can only assume that Terraform's call for git is doing something funky with ssh. Doesn't appear to be any debugging that can be done as it's all encapsulated with Terraform.

Does appear to be windows only, all my colleagues are using Linux with the same tf files without issues.

nhart-alf commented 5 years ago

Found a way to get this working. After looking at the Terraform source and other references to this issue, it appears that Terraform needs an environment variable for 'GIT_SSH_COMMAND' instead-of/in-addition-to 'GIT_SSH'.

In addition to this, the implementation of GIT_SSH_COMMAND isn't Windows friendly, so it needs the path to ssh.exe to be escaped for \ characters. The final value therefore is the below.

GIT_SSH_COMMAND = C:\\Windows\\System32\\OpenSSH\\ssh.exe

All other config remained the same as per my previous comment.

If someone from Hashicorp reads this, it could do with being much more obvious (documented) and possibly a better design for Windows.

smblee commented 4 years ago

Found a way to get this working. After looking at the Terraform source and other references to this issue, it appears that Terraform needs an environment variable for 'GIT_SSH_COMMAND' instead-of/in-addition-to 'GIT_SSH'.

In addition to this, the implementation of GIT_SSH_COMMAND isn't Windows friendly, so it needs the path to ssh.exe to be escaped for \ characters. The final value therefore is the below.

GIT_SSH_COMMAND = C:\\Windows\\System32\\OpenSSH\\ssh.exe

All other config remained the same as per my previous comment.

If someone from Hashicorp reads this, it could do with being much more obvious (documented) and possibly a better design for Windows.

This approach worked for me on windows. I had to run set GIT_SSH_COMMAND=C:\\Windows\\System32\\OpenSSH\\ssh.exe since i use cmder, but thanks for this!

bamb00 commented 4 years ago

Hi, I'm seeing the same issue running TF 0.12.21, Ubuntu 16.04.

Error: Failed to download module

Could not download module "storage_blob" (storage_blob.tf:1) source code from
"git@github.com:mycompanyname/infra-modules/terraform-azurerm-blobstorage?ref=sandbox":
error downloading
'ssh://git@github.com/mycompanyname/infra-modules/terraform-azurerm-blobstorage?ref=sandbox':
/usr/bin/git exited with 128: Cloning into
'.terraform/modules/storage_blob'...
Warning: Permanently added the RSA host key for IP address 'xxx.xx.xxx.xxx' to
the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
snolan-uturn commented 4 years ago

Found a way to get this working. After looking at the Terraform source and other references to this issue, it appears that Terraform needs an environment variable for 'GIT_SSH_COMMAND' instead-of/in-addition-to 'GIT_SSH'.

In addition to this, the implementation of GIT_SSH_COMMAND isn't Windows friendly, so it needs the path to ssh.exe to be escaped for \ characters. The final value therefore is the below.

GIT_SSH_COMMAND = C:\\Windows\\System32\\OpenSSH\\ssh.exe

All other config remained the same as per my previous comment.

If someone from Hashicorp reads this, it could do with being much more obvious (documented) and possibly a better design for Windows.

If you're only seeing the issue with Windows, then you are probably seeing what I have discussed here: https://github.com/hashicorp/terraform/issues/19232#issuecomment-620894910

dev2648e commented 3 years ago

I use pagent, so my env var had to be

GIT_SSH_COMMAND=C:\\Program\ Files\\PuTTY\\plink.exe

ADTC commented 2 years ago

This was definitely a problem for me on Windows. To get the SSH working with Terraform, I had to do:

set GIT_SSH_COMMAND=C:\\Windows\\System32\\OpenSSH\\ssh.exe

If you're not sure where your ssh.exe is, try:

where ssh

Note, the above set command only applies in the current session. To apply globally, you need to edit your system or user environment variables.