【问题标题】:How to add remote azure repo for terraform modules to make terraform code work on Azure pipelines如何为 terraform 模块添加远程 azure repo 以使 terraform 代码在 Azure 管道上工作
【发布时间】:2020-04-05 12:02:10
【问题描述】:

下面给出的源定义适用于 terraform 模块,但它有一个 PAT TOKEN。在本地 VM 以及 Azure Pipelines 上运行良好。这个问题是关于如何定义 terraform 模块的源定义,但没有硬编码 PAT TOKEN

代码的工作副本:

source = "git::https://<PAT TOKEN>@<AZURE DEVOPS URL>/DefaultCollection/<Project Name>y/_git/terraform-modules//<sub directory>"

我尝试了以下方法:

    git::https://<AZURE DEVOPS URL>/DefaultCollection/<Project Name>/_git/terraform-modules.git//<sub directory>

这给了我如下错误:

"git::https://<AZURE DEVOPS URL>/DefaultCollection/<Project Name>/_git/terraform-modules":
error downloading
'https://<AZURE DEVOPS URL>/DefaultCollection/<Project Name>/_git/terraform-modules':
/usr/bin/git exited with 128: Cloning into
'.terraform/modules/resource_group'...
fatal: could not read Username for 'https://<AZURE DEVOPS URL>':
terminal prompts disabled

添加了我的用户名,没有域部分,如下所示:

source                  = "git::https://<USERNAMEM@<AZURE DEVOPS URL>/DefaultCollection/<PROJECT NAME>/_git/terraform-modules.git//compute"

以下错误:

"git::https://<USERNAME>@<AZURE DEVOPS>/DefaultCollection/<PROJECT>/_git/terraform-modules.git":
error downloading
'https://<USERNAME>@<AZURE DEVOPS>/DefaultCollection/<PROJECT>/_git/terraform-modules.git':
/usr/bin/git exited with 128: Cloning into '.terraform/modules/sql_vms'...
fatal: could not read Password for
'https://<USERNAME>@<AZURE DEVOPS>': terminal prompts disabled

当构建管道可以在不指定用户名和密码的情况下进行结帐时,为什么我们必须在 terraform 代码中提及。

Azure 管道代理具有 git 凭据。不确定如果没有 PAT 令牌这是否可以工作?

【问题讨论】:

  • https://&lt;USERNAME&gt;@&lt;AZURE DEVOPS&gt;/DefaultCollection/&lt;PROJECT&gt;/_git/terraform-modules.git,如果您尝试通过这种格式访问 devops repos,您还可以使用 git credential 或 ssh。见this

标签: terraform azure-pipelines terraform-provider-azure azure-pipelines-release-task


【解决方案1】:

看看这个 - Is it possible to authenticate to a remote Git repository using the default windows credentials non interactively?

因此,在我们的案例中,我们发现在 terraform 之前运行 git config --global http.emptyAuth true 即可解决问题。不需要:@ 业务,除非您的 terraform 模块存储库是 LFS 存储库。但这不是我们的情况,所以我们不需要它。

【讨论】:

    猜你喜欢
    • 2021-10-23
    • 2021-04-28
    • 2020-03-29
    • 2016-11-24
    • 2021-10-25
    • 2020-06-14
    • 1970-01-01
    • 2022-10-25
    • 2020-03-17
    相关资源
    最近更新 更多