Terraform CustomScriptExtension报告无法下载文件

时间:2019-07-31 05:15:39

标签: terraform-provider-azure

G'day,

我正在运行Terraform扩展-CustomScriptExtension。但是,它报告了无法加载文件的错误。

resource "azurerm_virtual_machine_extension" "tf-vm-grpprd-ad-ext-install-addom" {
  count                      = "${var.count_ad_vm}"
  name                       = "${var.ad_base_hostname}${format("%02d",count.index+1)}-CSE"
  location                   = "${azurerm_resource_group.tf-rg-grpprd-core.location}"
  resource_group_name        = "${azurerm_resource_group.tf-rg-grpprd-core.name}"
  virtual_machine_name       = "${var.ad_base_hostname}${format("%02d",count.index+1)}"
  publisher                  = "${var.extension_publisher_ad}"
  type                       = "${var.extension_type_customerscriptextension}"
  auto_upgrade_minor_version = "true"
  type_handler_version       = "${var.extension_version_customscriptextension}"
  depends_on                 = ["azurerm_virtual_machine.tf-vm-grpprd-ad"]
   settings = <<SETTINGS
    {
        "fileUris": ["https://blackbeltteam.visualstudio.com/blackbeltteam/_git/groupsprod/scripts/Install_AD_Components.ps1"],
        "commandToExecute": "powershell.exe pwd",
        "commandToExecute": "powershell.exe ls",
        "commandToExecute": "powershell.exe -ExecutionPolicy unrestricted -NoProfile -NonInteractive -File Install_AD_Components.ps1"
    }
SETTINGS
}

我收到如下错误消息:

2019-07-31T01:17:20.0860444Z [1m[31mError: [0m[0m[1mCode="VMExtensionProvisioningError" Message="VM has reported a failure when processing extension 'grpprdad02-CSE'. Error message: \"Failed to download all specified files. Exiting. Error Message: The remote server returned an error: (404) Not Found.\"."[0m
2019-07-31T01:17:20.0860808Z 
2019-07-31T01:17:20.0861339Z [0m  on ad.tf line 250, in resource "azurerm_virtual_machine_extension" "tf-vm-grpprd-ad-ext-install-addom":
2019-07-31T01:17:20.0861901Z  250: resource "azurerm_virtual_machine_extension" "tf-vm-grpprd-ad-ext-install-addom" [4m{[0m
2019-07-31T01:17:20.0862336Z [0m
2019-07-31T01:17:20.0862897Z [0m[0m
2019-07-31T01:17:20.0894295Z [31m
2019-07-31T01:17:20.0895064Z [1m[31mError: [0m[0m[1mCode="VMExtensionProvisioningError" Message="VM has reported a failure when processing extension 'grpprdad01-CSE'. Error message: \"Failed to download all specified files. Exiting. Error Message: The remote server returned an error: (404) Not Found.\"."[0m
2019-07-31T01:17:20.0895600Z 
2019-07-31T01:17:20.0896889Z [0m  on ad.tf line 250, in resource "azurerm_virtual_machine_extension" "tf-vm-grpprd-ad-ext-install-addom":
2019-07-31T01:17:20.0897664Z  250: resource "azurerm_virtual_machine_extension" "tf-vm-grpprd-ad-ext-install-addom" [4m{[0m
2019-07-31T01:17:20.0898223Z [0m
2019-07-31T01:17:20.0898695Z [0m[0m
2019-07-31T01:17:20.0943083Z [31m
2019-07-31T01:17:20.0944168Z [1m[31mError: [0m[0m[1mcompute.VirtualMachineExtensionsClient#CreateOrUpdate: Failure sending request: StatusCode=404 -- Original Error: Code="ParentResourceNotFound" Message="Can not perform requested operation on nested resource. Parent resource 'grpprdaos01' not found."[0m
2019-07-31T01:17:20.0944773Z 
2019-07-31T01:17:20.0945288Z [0m  on aos.tf line 240, in resource "azurerm_virtual_machine_extension" "tf-vm-grpprd-aos-ext-join-ad":
2019-07-31T01:17:20.0945858Z  240: resource "azurerm_virtual_machine_extension" "tf-vm-grpprd-aos-ext-join-ad" [4m{[0m
2019-07-31T01:17:20.0946979Z [0m
2019-07-31T01:17:20.0947787Z [0m[0m
2019-07-31T01:17:20.0990513Z [31m
2019-07-31T01:17:20.0991014Z [1m[31mError: [0m[0m[1mcompute.VirtualMachineExtensionsClient#CreateOrUpdate: Failure sending request: StatusCode=404 -- Original Error: Code="ParentResourceNotFound" Message="Can not perform requested operation on nested resource. Parent resource 'grpprdaos02' not found."[0m
2019-07-31T01:17:20.0991108Z 
2019-07-31T01:17:20.1002906Z [0m  on aos.tf line 240, in resource "azurerm_virtual_machine_extension" "tf-vm-grpprd-aos-ext-join-ad":
2019-07-31T01:17:20.1003501Z  240: resource "azurerm_virtual_machine_extension" "tf-vm-grpprd-aos-ext-join-ad" [4m{[0m

它不表示它执行失败的命令,在哪里运行等,我如何理解导致悲伤的原因。

2 个答案:

答案 0 :(得分:1)

问题可能是当您访问URI https://blackbeltteam.visualstudio.com/blackbeltteam/_git/groupsprod/scripts/Install_AD_Components.ps1时找不到资源。脚本位置可以在任何位置,只要VM可以路由到该端点(例如GitHub或内部文件服务器)即可。

您可以确保SETTINGS中的文件Uri可以从您的VM中检索资源。如果需要从外部下载脚本,则需要打开其他防火墙和网络安全组端口。

有关更多参考:

答案 1 :(得分:0)

我遇到了同样的问题,最终发现这是由于blob存储中的文件名中包含大写字母!希望这可以帮助其他人避免同样的问题。