首页 > 解决方案 > 无法从 azure repo(私人 repo)下载 terraform 模块

问题描述

我的 terraform-modules 存储库位置是这样的:

https://teamabc.visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster

我在根级别有三个目录/模块,即计算、资源组和 sqlserver。但是,当我运行 terraform init. terraform 无法下载所需的模块。

主文件

module "app_vms" {
  source                = "https://teamabc.visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster"
  rg_name               = var.resource_group_name
  location              = module.resource_group.external_rg_location
  vnet_name             = var.virtual_network_name
  subnet_name           = var.sql_subnet_name
  app_nsg               = var.application_nsg
  vm_count              = var.count_vm
  base_hostname         = var.app_host_basename
  sto_acc_suffix        = var.storage_account_suffix
  vm_size               = var.virtual_machine_size
  vm_publisher          = var.virtual_machine_image_publisher
  vm_offer              = var.virtual_machine_image_offer
  vm_sku                = var.virtual_machine_image_sku
  vm_img_version        = var.virtual_machine_image_version
  username              = var.username
  password              = var.password
  allowed_source_ips    = var.ip_list
}

module "resource_group" {
  source                = "https://teamabc.visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fresourcegroup&version=GBmaster"
  rg_name               = "test_rg"
}

module "azure_paas_sqlserver" {
  source                = "https://teamabc.visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fsqlserver&version=GBmaster"  
}

它给了我一系列错误,如下所示:(示例仅给出并非所有错误,因为它们是相同的)

Error: Failed to download module

Could not download module "sql_vms" (main.tf:1) source code from
"https://teamabc.visualstudio.com/dummpproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster":
error downloading
'https://teamabc.visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster':
no source URL was returned


Error: Failed to download module

Could not download module "sql_vms" (main.tf:1) source code from
"https://teamabc.visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster":
error downloading
'https://teamabc.visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster':
no source URL was returned

我试图删除https://部分但没有运气。回购确实需要用户名和密码才能登录。

想知道我是否应该在 github 上进行公开回购?但组织内部的推动是使用 Azure Repos。


发表第一条评论


感谢您的领导,我确实尝试过,但仍然没有魅力。

我的源网址现在如下所示

  source                = "git::https://teamabc:lfithww4xpp4eksvoimgzkpi3ugu6xvrkf26mfq3jth3642jgyoa@visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster"

我收到以下错误:

Error: Failed to download module

Could not download module "sql_vms" (main.tf:1) source code from
"git::https://teamabc:lfithww4xpp4eksvoimgzkpi3ugu6xvrkf26mfq3jth3642jgyoa@visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster":
error downloading
'https://teamabc:lfithww4xpp4eksvoimgzkpi3ugu6xvrkf26mfq3jth3642jgyoa@visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster':
/usr/bin/git exited with 128: Cloning into '.terraform/modules/sql_vms'...
fatal: repository
'https://teamabc:lfithww4xpp4eksvoimgzkpi3ugu6xvrkf26mfq3jth3642jgyoa@visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster/'
not found

这里:

teamabc.visuastudio.com是父 azure devops url

dummyproject项目名称

查尔斯回应后

Error: Failed to download module

Could not download module "sql_vms" (main.tf:1) source code from
"git::https://teamabc:lfithww4xpp4eksvoimgzkpi3ugu6xvrkf26mfq3jth3642jgyoa@visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster.git":
error downloading
'https://teamabc:lfithww4xpp4eksvoimgzkpi3ugu6xvrkf26mfq3jth3642jgyoa@visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster.git':
/usr/bin/git exited with 128: Cloning into '.terraform/modules/sql_vms'...
fatal: repository
'https://teamabc:lfithww4xpp4eksvoimgzkpi3ugu6xvrkf26mfq3jth3642jgyoa@visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster.git/'
not found

标签: terraformterraform-provider-azureazure-repos

解决方案


您可以查看Generic Git Repository,该 URL 应该是 Git URL。最后,它应该是这样的:

source                = "git::https://teamabc:lfithww4xpp4eksvoimgzkpi3ugu6xvrkf26mfq3jth3642jgyoa@visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster.git"

或者您可以从 Git 存储库中选择一个分支,如下所示:

source                = "git::https://teamabc:lfithww4xpp4eksvoimgzkpi3ugu6xvrkf26mfq3jth3642jgyoa@visualstudio.com/dummyproject/_git/terraform-modules?path=%2Fcompute&version=GBmaster.git?ref=<branch>"

最后,通过以下命令使其工作:

git::https://<PAT TOKEN>@<Azure DevOps URL>/DefaultCollection/<PROJECT NAME>/_git/<REPO NAME>//<sub directory>

推荐阅读