Terraform不尊重SSH配置GIT



我的Terraform模块在通过SSH键访问的私人位式存储库中。

我不知道git命令terraform运行什么或如何更改auth,但是它似乎正在使用其他ssh config。

这是我的.tf文件:

module "sdfsdfs" {
  source = "git::ssh://bitbucket.org/mycomp/my-module-root//submodule"
}

我正在用詹金斯管道运行此操作,并且正在编辑SSH配置以使用特定键。我已经证明了这项工作:

sshagent (credentials: ['my-ssh-key']) {
    bat 'git clone git@bitbucket.org:mycomp/my-module.git'
}

SSH配置经过正确修改,并在Jenkins中使用我的密钥存储。

我不知道Terraform实际上是从Git Repo中拔出的,但它并不尊重SSH配置:

sshagent (credentials: ['my-ssh-key']) {
    bat 'terraform init'
}

我得到此错误:

C:Program FilesGitcmdgit.exe exited with 128: Cloning into 
'.terraformmodulesc760b746e09bd59ba86aae13dc9e9959'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Terraform在这里做什么或不做什么?我只想为此会话进行配置,因此不可能为我的Jenkins服务器设置全局SSH配置。

这部分是一个bitbucket的限制,部分是我不彻底阅读文档。

Bitbucket API似乎不支持SSH或其他内容,因为Terraform Docs只有示例https https。

将其当作通用的git repo作品处理:

  source = "git::ssh://git@bitbucket.org/mycomp/myrepo.git//my-sub-module"

我知道这个问题真的很旧,但我可能会帮助其他可能遇到这个问题的人。在Windows中帮助我的是将环境变量git_ssh_command设置为ssh.exe的路径。在CMD中,运行:

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

最新更新