在Terraform中定义Azure VM CustomScriptExtension(预期状态为“元素".遇到名称为“,名称空间为"\"."的“文本") [英] Defining Azure VM CustomScriptExtension in Terraform (Expecting state 'Element'.. Encountered 'Text' with name '', namespace ''. \".")

查看:176
本文介绍了在Terraform中定义Azure VM CustomScriptExtension(预期状态为“元素".遇到名称为“,名称空间为"\"."的“文本")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Terraform中为Azure VM定义了CustomScriptExtension:

I defined a CustomScriptExtension for Azure VM in Terraform:

resource "azurerm_virtual_machine_extension" "test" {
    name = "WinRM"
    location = "South Central US"
    resource_group_name = "${azurerm_resource_group.test.name}"
    virtual_machine_name = "${azurerm_virtual_machine.test.name}"
    publisher = "Microsoft.Compute"
    type = "CustomScriptExtension"
    type_handler_version = "1.8"

    settings = <<SETTINGS
    {
        "fileUris": "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1",
        "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File ConfigureRemotingForAnsible.ps1"
    }
SETTINGS

}

但是我得到了(相同的错误在VM扩展的Azure门户中可见):

However I get (the same error is visible in Azure portal in VM extensions):

azurerm_virtual_machine_extension.test:compute.VirtualMachineExtensionsClient#CreateOrUpdate:发送请求失败:StatusCode = 200-原始错误:长时间运行的操作终止,状态为"Failed":Code ="VMExtensionProvisioningError" Message ="VM在处理时报告了失败扩展名'WinRM'.错误消息:\无效的处理程序配置.正在退出.错误消息:预期状态为元素".遇到名称为名称空间"的文本". \.

azurerm_virtual_machine_extension.test: compute.VirtualMachineExtensionsClient#CreateOrUpdate: Failure sending request: StatusCode=200 -- Original Error: Long running operation terminated with status 'Failed': Code="VMExtensionProvisioningError" Message="VM has reported a failure when processing extension 'WinRM'. Error message: \"Invalid handler configuration. Exiting. Error Message: Expecting state 'Element'.. Encountered 'Text' with name '', namespace ''. \"."

Azure部署可以正常工作(以下相关摘录):

The same parameters executed as an Azure deployment works with no problems (relevant excerpts below):

"fileUris": {
  "type": "string",
  "defaultValue": "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1",
  "metadata": {
    "description": "The uri list of files. Split by a space."
  }
},

"settings": {
  "fileUris": "[split(parameters('fileUris'), ' ')]",
  "commandToExecute": "[parameters('commandToExecute')]"
}

我是否缺少某些东西,或者它是Terraform中的错误?

Am I missing something, or is it a bug in Terraform?

一些调试:

  • 如果我将设置替换为:

  • If I replace the settings with just:

{
    "commandToExecute": "mkdir C:\\Test"
}

创建目录,所以问题出在fileUris.

the directory gets created, so the problem is with fileUris.

如果我将设置JSON中的fileUris替换为fileUri(应该是错误的):

If I replace fileUris in the settings JSON with fileUri (which should be wrong):

{
    "fileUri": "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1",
    "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File ConfigureRemotingForAnsible.ps1"
}

没有Encountered 'Text' with name '', namespace ''. \".错误,powershell.exe触发并报告缺少ConfigureRemotingForAnsible.ps1.

there is no the Encountered 'Text' with name '', namespace ''. \". error, powershell.exe fires and reports missing ConfigureRemotingForAnsible.ps1.

推荐答案

错误消息:\无效的处理程序配置.正在退出.错误消息:预期状态为'Element'..遇到了'Text',名称为",名称空间为."."

Error message: \"Invalid handler configuration. Exiting. Error Message: Expecting state 'Element'.. Encountered 'Text' with name '', namespace ''. \"."

众所周知,fileUris的值类型应为 array ,我已经在Azure部署中对其进行了测试,如果将fileUris配置为字符串值,则可以得到与您提供的错误相同.

As I known, the value type of fileUris should be an array, I have tested it with Azure deployment, if I configure fileUris as a string value, then I could get the same error as you provided.

更新

fileUris应该如下所示:

"settings": {
  "fileUris": [
    "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1"
  ],
  "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File ConfigureRemotingForAnsible.ps1"
}

这篇关于在Terraform中定义Azure VM CustomScriptExtension(预期状态为“元素".遇到名称为“,名称空间为"\"."的“文本")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆