【问题标题】:Issues using bitbucket git repository source for downloading a module over SSH使用 bitbucket git 存储库源通过 SSH 下载模块的问题
【发布时间】:2019-05-26 14:59:02
【问题描述】:

从本地源调用模块时一切正常,但是我决定重构 Terraform 代码以使用 git 存储库来存储模块。

我在我们的 BitBucket 帐户中创建了一个名为 terraform-modules 的新存储库,并将模块的源属性重构为具有以下结构:

source     = "git::ssh://git@bitbucket.org:carepaydev/terraform-modules.git//modules/iam/iam_roles/assumable_role"

调用terraform init 时出现以下错误:

Error downloading modules: Error loading modules: error downloading 'ssh://git@bitbucket.org:<username>/terraform-modules.git': /usr/local/bin/git exited with 128: Cloning into '.terraform/modules/caf541f5e5ccbb1d204bce3b94091014'...
ssh: Could not resolve hostname bitbucket.org:<username>: nodename nor servname provided, or not known
fatal: Could not read from remote repository.

使用 git clone 克隆存储库确实有效。我尝试将TF_LOG env var 设置为TRACE,看看这是否会给我更多的洞察力,但这并没有帮助。

任何线索为什么会失败?

【问题讨论】:

    标签: git bitbucket terraform


    【解决方案1】:

    ssh://git@bitbucket.orgusername/repo之间的冒号改为斜杠:

    ssh://git@bitbucket.org/username/repo

    在该格式中,冒号表示备用端口 - 如果您想使用ssh://git@altssh.bitbucket.org:443/username/repo,这很有用,并且类似于您为其他协议(如 HTTP)指定备用端口的方式。

    【讨论】:

    • 是否可以使其通用,以便所有团队成员都可以使用它?喜欢使用一些环境变量?
    • 这两种形式已经是通用的。此处列出的username 是repo 的owner,可以是团队或个人;更改 username 会将请求发送到不同的存储库。
    【解决方案2】:

    您在尝试访问私有存储库时遇到了与 hashicorp/terraform issue 12696 类似的错误。

    至少,尝试设置git config --global core.sshCommand "ssh -Tvv",以便查看Terraform 在git clone 进程中实际使用的私钥。

    【讨论】:

      猜你喜欢
      • 2012-06-10
      • 1970-01-01
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      • 2018-01-16
      • 1970-01-01
      • 2010-12-16
      • 1970-01-01
      相关资源
      最近更新 更多