gpt4 book ai didi

windows - Terraform azurerm_virtual_machine_extension错误 "extension operations are disallowed"

转载 作者:行者123 更新时间:2023-12-02 21:10:00 35 4
gpt4 key购买 nike

我编写了一个用于创建 Azure Windows VM 的 Terraform 模板。我需要将虚拟机配置为启用 PowerShell 远程处理,以便发布管道能够执行 Powershell 脚本。创建 VM 后,我可以通过 RDP 连接到 VM,并执行启用 Powershell 远程处理所需的所有操作,但是,如果我可以编写所有这些脚本,以便可以在发布管道中执行,那就更理想了。有两件事可以阻止这种情况。

第一个问题,也是这个问题的主题,我必须运行“WinRM Quickconfig”。我的模板可以正常工作,这样当我在创建后对虚拟机执行 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 中配置虚拟机,以便设置 LocalAccountTokenFilterPolicy,并且无需通过 RDP 到虚拟机来运行“WinRM 快速配置”。经过一些研究,我似乎可以使用资源 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 block ,但它被视为无效属性而被拒绝。我还尝试将其添加到 os_profile_windows_config block 中,但在那里也无效。

我在 Microsoft 文档中找到了有关 osProfile.allowExtensionOperations 属性的声明:

"This may only be set to False when no extensions are present on the virtual machine."

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

这对我来说意味着该属性默认为 True,但实际上并没有这么说,而且它的行为肯定不是那样的。 Terraform 中有没有办法将 osProfile.alowExtensionOperations 设置为 true?

最佳答案

使用 Terraform 添加扩展时遇到同样的问题,我创建了一个 Windows 2016 自定义镜像,

提供商“azurerm”版本=“2.0.0”地形 0.12.24

Terraform apply 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."

关于windows - Terraform azurerm_virtual_machine_extension错误 "extension operations are disallowed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58173834/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com