【问题标题】:Terraform module in private git repo私有 git 存储库中的 Terraform 模块
【发布时间】:2020-08-26 02:36:17
【问题描述】:

我在私有 gitlab 存储库中创建了一个 terraform 模块。 另一个 repo 中的 terraform 资源需要使用这个模块。

module "my_module" {
  source = "git::https://gitlab.example.com/my-repo.git"
}

这在本地工作,但不在我们的 CI 管道中,因为它需要用户名和密码。所以我生成了一对并尝试了这个:

module "email_sns" {
  source = "git::https://${var.username}:${var.password}@gitlab.example.com/my-repo.git"
}

这不起作用,因为 terraform 不允许在 source 中使用变量。

剩下的唯一选择是,afaik 是使用 git credential helper 并为其添加用户名和密码。 但是store 助手将它们存储为纯文本。我不想要这个。 我可以看到有一个使用 cache 作为助手的选项,但是如何将用户名和密码存储在 CI 中? 或者有没有其他方法可以解决这个问题?

【问题讨论】:

  • 您确实需要在管道中而不是在 TF 配置中处理此问题。至于纯文本问题,有多种秘密管理解决方案可用于避免该问题。

标签: git terraform gitlab-ci


【解决方案1】:

您必须为此使用 ssh 密钥。使用terraform模块在repo中创建新密钥,然后将此密钥添加到执行模块的运行器中。您可以找到更多详细信息如何创建ssh密钥on Gitlab documentation page

这也意味着,您应该将源字符串从 https 切换到 ssh 以使其正常工作。

【讨论】:

    猜你喜欢
    • 2020-10-03
    • 2012-05-24
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多