【问题标题】:Terraform not respecting ssh config for gitTerraform 不尊重 git 的 ssh 配置
【发布时间】:2018-05-28 23:03:31
【问题描述】:

我的 terraform 模块位于通过 ssh 密钥访问的私有 bitbucket 存储库中。

我不知道 terraform 运行什么 git 命令或如何更改身份验证,但它似乎使用了不同的 ssh 配置。

这是我的.tf 文件:

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

我在 jenkins 管道中运行它,并且我正在编辑 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 Files\Git\cmd\git.exe exited with 128: Cloning into 
'.terraform\modules\c760b746e09bd59ba86aae13dc9e9959'...

Permission denied (publickey).

fatal: Could not read from remote repository.

terraform 在这里做什么或不做什么?我只想为此会话进行配置,因此无法为我的 jenkins 服务器设置全局 ssh 配置。

【问题讨论】:

    标签: git jenkins jenkins-plugins jenkins-pipeline terraform


    【解决方案1】:

    这部分是位桶限制,部分是我没有彻底阅读the docs

    bitbucket api 似乎不支持 ssh 或其他东西,因为 terraform 文档只有 https 和 bitbucket 的示例。

    将其视为通用 git repo 有效:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-04
        • 2013-06-05
        • 2019-03-10
        • 1970-01-01
        • 2017-07-13
        • 1970-01-01
        相关资源
        最近更新 更多