Azure 构建管道报告无法读取密码

Azure build pipeline reports cannot read password

我的 main.tf 文件如下所示

module "sql_vms" {
  source                  = "git::https://iuclk3yjmv7qgglu3igkgxffacc2pzsv7nyhs44wmsjnrvccctaq@dev.azure.com/sampleuser/my_code/_git/terraform_modules.git//compute"
  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.sql_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
}

模块在同一个存储库中,技术上不正确,但现在,我想使用 Azure 存储库,它有一个 terraform 模块并从 TF 模块创建多个 VM。

我收到如下错误

2020-08-23T02:27:38.1439274Z [command]/usr/local/bin/terraform init -backend-config=storage_account_name=stoaccautomationnonprod -backend-config=container_name=stoacccon01nonprod -backend-config=key=nonprod.tfstate -backend-config=resource_group_name=automation -backend-config=arm_subscription_id=cc800481-b728-4d8f-81be-e80b955d346e -backend-config=arm_tenant_id=*** -backend-config=arm_client_id=*** -backend-config=arm_client_secret=***
2020-08-23T02:27:38.1441494Z [0m[1mInitializing modules...[0m
2020-08-23T02:27:38.1442513Z Downloading git::https://iuclk3yjmv7qgglu3igkgxffacc2pzsv7nyhs44wmsjnrvccctaq@dev.azure.com/sampleuser/my_code/_git/terraform_modules.git for sql_vms...
2020-08-23T02:27:38.1443347Z [31m
2020-08-23T02:27:38.1444113Z [1m[31mError: [0m[0m[1mFailed to download module[0m
2020-08-23T02:27:38.1444608Z 
2020-08-23T02:27:38.1445408Z [0mCould not download module "sql_vms" (main.tf:1) source code from
2020-08-23T02:27:38.1446189Z "git::https://iuclk3yjmv7qgglu3igkgxffacc2pzsv7nyhs44wmsjnrvccctaq@dev.azure.com/sampleuser/my_code/_git/terraform_modules.git":
2020-08-23T02:27:38.1446845Z error downloading
2020-08-23T02:27:38.1447746Z 'https://iuclk3yjmv7qgglu3igkgxffacc2pzsv7nyhs44wmsjnrvccctaq@dev.azure.com/sampleuser/my_code/_git/terraform_modules.git':
2020-08-23T02:27:38.1448669Z /usr/bin/git exited with 128: Cloning into '.terraform/modules/sql_vms'...
2020-08-23T02:27:38.1449408Z fatal: could not read Password for
2020-08-23T02:27:38.1450157Z 'https://iuclk3yjmv7qgglu3igkgxffacc2pzsv7nyhs44wmsjnrvccctaq@dev.azure.com':
2020-08-23T02:27:38.1450684Z terminal prompts disabled
2020-08-23T02:27:38.1450936Z 
2020-08-23T02:27:38.1451324Z [0m[0m
2020-08-23T02:27:38.1451716Z [31m
2020-08-23T02:27:38.1452230Z [1m[31mError: [0m[0m[1mFailed to download module[0m
2020-08-23T02:27:38.1452525Z 
2020-08-23T02:27:38.1453109Z [0mCould not download module "sql_vms" (main.tf:1) source code from
2020-08-23T02:27:38.1454386Z "git::https://iuclk3yjmv7qgglu3igkgxffacc2pzsv7nyhs44wmsjnrvccctaq@dev.azure.com/sampleuser/my_code/_git/terraform_modules.git":
2020-08-23T02:27:38.1454903Z error downloading
2020-08-23T02:27:38.1456723Z 'https://iuclk3yjmv7qgglu3igkgxffacc2pzsv7nyhs44wmsjnrvccctaq@dev.azure.com/sampleuser/my_code/_git/terraform_modules.git':
2020-08-23T02:27:38.1457540Z /usr/bin/git exited with 128: Cloning into '.terraform/modules/sql_vms'...
2020-08-23T02:27:38.1458063Z fatal: could not read Password for
2020-08-23T02:27:38.1458813Z 'https://iuclk3yjmv7qgglu3igkgxffacc2pzsv7nyhs44wmsjnrvccctaq@dev.azure.com':
2020-08-23T02:27:38.1459301Z terminal prompts disabled
2020-08-23T02:27:38.1459470Z 
2020-08-23T02:27:38.1459765Z [0m[0m
2020-08-23T02:27:38.1459896Z 
2020-08-23T02:27:38.1496541Z ##[error]Terraform command 'init' failed with exit code '1'.:  Failed to download module |  Failed to download module
2020-08-23T02:27:38.1786437Z ##[section]Finishing: terraform init

我正在考虑使用 SSH 而不是 HTTPS 和 PAT 令牌,不幸的是我不知道如何在 Microsoft 代理上添加 public 密钥?

请协助

使用SSH key拉取Terraform模块时,需要自己生成SSH key。然后在 DevOps 中创建一个 SSH 密钥:

然后您需要将管道变量组中的私钥作为安全文件上传,并添加在您的代理中安装SSH 的步骤。在这样的代理作业中安装 SSH:

获取有关 use SSH to pull the remote Terraform module 的更多详细信息。