![](/img/trans.png)
[英]Use terraform module from another private repo with git submodule
[英]Terraform module in private git repo
我在私人 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
helper 將它們存儲為純文本。 我不要這個。 我可以看到有一個選項可以使用cache
作為幫助程序,但是如何在 CI 中存儲用戶名和密碼? 或者有沒有其他方法可以解決這個問題?
為此,您必須使用 ssh 密鑰。 使用terraform
模塊在 repo 中創建新密鑰,然后將此密鑰添加到執行該模塊的運行程序中。您可以在 Gitlab 文檔頁面上找到如何創建 ssh 密鑰的更多詳細信息
這也意味着,您應該將源字符串從https
切換到ssh
以使其正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.