【问题标题】:Multiple VMExtensions per handler not supported for OS type 'Windows' - terraform(CustomScriptExtension)操作系统类型“Windows”不支持每个处理程序多个 VMExtensions - terraform(CustomScriptExtension)
【发布时间】:2021-03-02 17:15:26
【问题描述】:

我正在通过 terraform 创建以下这些扩展作为 vm 模块的一部分。 第一个扩展(customScript Extenison)被创建。

resource "azurerm_virtual_machine_extension" "dsm_activate" {
  name                 = "DSM-Activation_Extension"
  virtual_machine_id   = azurerm_virtual_machine.vm.id
  publisher            = "Microsoft.Compute"
  type                 = "CustomScriptExtension"
  type_handler_version = "1.9"
  depends_on           = [azurerm_virtual_machine.vm]

  settings = <<-BASE_SETTINGS
  {
     "fileUris": ["https://sstsv2xxxxxxxtmztf.blob.core.windows.net/scripts/windows_dsm_activate.ps1"]
  }
BASE_SETTINGS

  protected_settings = <<-PROTECTED_SETTINGS
  {
    "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File windows_dsm_activate.ps1",
    "storageAccountName": "${var.storage_account}",
    "storageAccountKey": "${var.storage_account_key}"
  }
PROTECTED_SETTINGS
}

resource "azurerm_virtual_machine_extension" "initialize_disk" {
  name                  = "Initialize-Disk-VMExtension"
  virtual_machine_id    = azurerm_virtual_machine.vm.id
  publisher             = "Microsoft.Compute"
  type                  = "CustomScriptExtension"
  type_handler_version  = "1.10"
  depends_on            = ["azurerm_virtual_machine.vm","azurerm_virtual_machine_extension.dsm_activate", "azurerm_virtual_machine_extension.da_extension","azurerm_virtual_machine_extension.nw_extension"]

 
  settings = <<SETTINGS
    {
    }
SETTINGS
  protected_settings = <<PROTECTED_SETTINGS
    {
        "commandToExecute": "powershell Initialize-Disk -FriendlyName (Get-Disk -Number 2).FriendlyName -PartitionStyle MBR -PassThru; powershell New-Partition -DiskNumber (Get-Disk -Number 2).DiskNumber -AssignDriveLetter -UseMaximumSize; powershell Format-Volume -DriveLetter F -FileSystem NTFS -NewFileSystemLabel 'DATA' -Confirm:0"
    }
  PROTECTED_SETTINGS
}

但是,当它尝试执行第二个 customScriptExtension 时代码失败,并出现以下错误:

Multiple VMExtensions per handler not supported for OS type 'Windows'. VMExtension with handler 'Microsoft.Compute.CustomScriptExtension' already added or specified in input

如何修改上述脚本以执行两个自定义脚本。

【问题讨论】:

    标签: powershell terraform terraform-provider-azure


    【解决方案1】:

    根据Microsoft documentation,这是不支持的。见注释

    一次只能在虚拟机上安装一个版本的扩展程序 及时,在同一个资源管理器中指定自定义脚本两次 同一 VM 的模板将失败。

    由于您使用的是 1.9 和 1.10 版本,因此尚不清楚它是两个版本,还是两个扩展。不管提供的其他示例如何,我都建议您采用第二个扩展中的代码示例,并创建一个文件以包含在您的第一个扩展 fileUris 中。

    【讨论】:

      【解决方案2】:

      支持多个脚本执行,但您需要将这些执行嵌入到一个主 powershell 文件中。

      只需创建 powershell 文件,您可以在其中执行其他两个文件,如文档中所述:

      【讨论】:

        猜你喜欢
        • 2017-08-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-21
        • 2015-10-25
        • 1970-01-01
        • 2019-10-18
        • 2023-03-17
        相关资源
        最近更新 更多