Terraform azurerm_virtual_machine_extension错误“不允许进行扩展操作”

问题描述 投票:3回答:1

我已经编写了创建Azure Windows VM的Terraform模板。我需要将VM配置为启用PowerShell Remoting,以使发布管道能够执行Powershell脚本。创建虚拟机之后,我可以将RDP发送到虚拟机,并做所有需要启用Powershell远程处理的工作,但是,如果我可以编写所有脚本以使其可以在Release管道中执行,那将是理想的选择。有两点可以防止这种情况。

首先,这个问题的主题是,我必须运行“ WinRM quickconfig”。我的模板可以正常工作,以便在创建VM之后对我执行RDP时,当我运行“ WinRM quickconfig”时收到以下响应:

WinRM service is already running on this machine.
WinRM is not set up to allow remote access to this machine for management.
The following changes must be made:

Configure LocalAccountTokenFilterPolicy to grant administrative rights remotely to local users.

Make these changes [y/n]?

我想在Terraform中配置VM,因此设置了LocalAccountTokenFilterPolicy,因此RDP无需在VM中运行“ WinRM quickconfig”。经过一些研究,看来我可以使用资源azure_virtual_machine_extension做到这一点。我将此添加到我的模板中:

resource "azurerm_virtual_machine_extension" "vmx" {
  name                 = "hostname"
  location             = "${var.location}"
  resource_group_name  = "${var.vm-resource-group-name}"
  virtual_machine_name = "${azurerm_virtual_machine.vm.name}"
  publisher            = "Microsoft.Azure.Extensions"
  type                 = "CustomScript"
  type_handler_version = "2.0"

settings = <<SETTINGS
    {
          # "commandToExecute": "powershell Set-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System' -Name 'LocalAccountTokenFilterPolicy' -Value 1 -Force"
    }
SETTINGS
}

当我应用此方法时,出现错误:

Error: compute.VirtualMachineExtensionsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> Code="OperationNotAllowed" Message="This operation cannot be performed when extension operations are disallowed. To allow, please ensure VM Agent is installed on the VM and the osProfile.allowExtensionOperations property is true."

我找不到任何有关如何将allowExtensionOperations属性设置为true的Terraform文档。一时兴起,我尝试将属性“ allow_extension_operations”添加到azurerm_virtual_machine资源中的os_profile块中,但被拒绝为无效属性。我也尝试过将其添加到os_profile_windows_config块中,并且在此也不有效。

[我在Microsoft文档中找到有关osProfile.allowExtensionOperations属性的声明,该声明说:

“仅​​当虚拟机上没有扩展名时,才可以将其设置为False。”

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.management.compute.models.osprofile.allowextensionoperations?view=azure-dotnet

这向我暗示该属性默认情况下为True,但实际上并没有这样说,而且它的行为肯定不是那样。 Terraform中是否可以将osProfile.alowExtensionOperations设置为true?]

windows virtual-machine terraform powershell-remoting azure-rm
1个回答
0
投票
提供者“ azurerm”版本=“ 2.0.0”Terraform 0.12.24

Terraform套用错误:compute.VirtualMachineExtensionsClient#CreateOrUpdate:发送请求失败:StatusCode = 0-原始错误:autorest / azure:服务返回了错误。Status = Code =“ OperationNotAllowed” Message =“禁止扩展操作时无法执行此操作。要允许,请确保VM上已安装VM Agent,并且osProfile.allowExtensionOperations属性为true。”

© www.soinside.com 2019 - 2024. All rights reserved.