无法将 JSON 数组反序列化为类型 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.TemplateResourceCopy'
Cannot deserialize JSON array into type 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.TemplateResourceCopy'
该模板的目的是将子网添加到现有 Vnet,但在使用 powershell 命令执行它时
New-AzureRmResourceGroupDeployment -Name testing -ResourceGroupName rgname -TemplateFile C:\Test\deploy.json -TemplateParameterFile C:\Test\parameterfile.json
显示如下错误,实在看不懂means.Here是什么错误*
“错误:代码=无效请求内容;消息=请求内容无效,无法反序列化:‘无法填充 JSON
数组本体'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.TemplateResourceCopy'。路径 'properties.template.resources[0].copy' "*
以下是我的输入文件(parameter.json)
{
"VNetSettings":{
"value":{
"name":"VNet2",
"addressPrefixes":"10.0.0.0/16",
"subnets":[
{
"name": "sub5",
"addressPrefix": "10.0.5.0/24"
},
{
"name":"sub6",
"addressPrefix":"10.0.6.0/24"
}
]
}
}
}
以下是我的模板(deploy.json)
{
"contentversion":"1.0.0.0",
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"parameters":{
"VNetSettings":
{"type":"object"},
"noofsubnets":
{
"type":"int"
}
},
"resources":
[
{
"type":"Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2015-06-15",
"location":"[resourceGroup().location]",
"copy": [
{
"name":"subnets",
"count":"[parameters('noofsubnets')]",
"input": {
"name": "[concat(parameters('VNetSettings').name, '/',parameters('VNetSettings').subnets[copyIndex('subnets')].name)]",
"properties":{
"addressPrefix": "[parameters('VNetSettings').subnets[copyIndex('subnets')].addressPrefix]"
}
}
}
]
}
]
}
我想错误应该在复制语句中和周围。
如果您创建一个子网资源,您需要json像一个完整的资源一样构建:
"name": "[concat('bla/bla-', copyIndex())]",
"type": xxx,
"apiVersion": xxx,
"location": xxx,
"copy": {
"name": xxx,
"count": xxx
},
"properties": {
"addressPrefix": xxx
}
并且只使用 copyIndex()
功能。没有 'subnets'
这里是 solution.Thanks 至 @4c74356b41 的线索。
{
"contentversion":"1.0.0.0",
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"parameters":{
"VNetSettings":{"type":"object"},
"noofsubnets":
{
"type":"int"
}
},
"variables":
{
"vnetname":"[parameters('VNetSettings').name]"
},
"resources":
[
{
"type":"Microsoft.Network/virtualNetworks/subnets",
"name": "[concat(variables('vnetname'), '/',parameters('VNetSettings').subnets[copyIndex()].name)]",
"apiVersion": "2015-06-15",
"location":"[resourceGroup().location]",
"properties":{
"addressPrefix": "[parameters('VNetSettings').subnets[copyIndex()].addressPrefix]"
},
"copy":{
"name":"subnetcopy",
"count":"[parameters('noofsubnets')]"
}
}
]
}
该模板的目的是将子网添加到现有 Vnet,但在使用 powershell 命令执行它时
New-AzureRmResourceGroupDeployment -Name testing -ResourceGroupName rgname -TemplateFile C:\Test\deploy.json -TemplateParameterFile C:\Test\parameterfile.json
显示如下错误,实在看不懂means.Here是什么错误* “错误:代码=无效请求内容;消息=请求内容无效,无法反序列化:‘无法填充 JSON 数组本体'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.TemplateResourceCopy'。路径 'properties.template.resources[0].copy' "*
以下是我的输入文件(parameter.json)
{
"VNetSettings":{
"value":{
"name":"VNet2",
"addressPrefixes":"10.0.0.0/16",
"subnets":[
{
"name": "sub5",
"addressPrefix": "10.0.5.0/24"
},
{
"name":"sub6",
"addressPrefix":"10.0.6.0/24"
}
]
}
}
}
以下是我的模板(deploy.json)
{
"contentversion":"1.0.0.0",
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"parameters":{
"VNetSettings":
{"type":"object"},
"noofsubnets":
{
"type":"int"
}
},
"resources":
[
{
"type":"Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2015-06-15",
"location":"[resourceGroup().location]",
"copy": [
{
"name":"subnets",
"count":"[parameters('noofsubnets')]",
"input": {
"name": "[concat(parameters('VNetSettings').name, '/',parameters('VNetSettings').subnets[copyIndex('subnets')].name)]",
"properties":{
"addressPrefix": "[parameters('VNetSettings').subnets[copyIndex('subnets')].addressPrefix]"
}
}
}
]
}
]
}
我想错误应该在复制语句中和周围。
如果您创建一个子网资源,您需要json像一个完整的资源一样构建:
"name": "[concat('bla/bla-', copyIndex())]",
"type": xxx,
"apiVersion": xxx,
"location": xxx,
"copy": {
"name": xxx,
"count": xxx
},
"properties": {
"addressPrefix": xxx
}
并且只使用 copyIndex()
功能。没有 'subnets'
这里是 solution.Thanks 至 @4c74356b41 的线索。
{
"contentversion":"1.0.0.0",
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"parameters":{
"VNetSettings":{"type":"object"},
"noofsubnets":
{
"type":"int"
}
},
"variables":
{
"vnetname":"[parameters('VNetSettings').name]"
},
"resources":
[
{
"type":"Microsoft.Network/virtualNetworks/subnets",
"name": "[concat(variables('vnetname'), '/',parameters('VNetSettings').subnets[copyIndex()].name)]",
"apiVersion": "2015-06-15",
"location":"[resourceGroup().location]",
"properties":{
"addressPrefix": "[parameters('VNetSettings').subnets[copyIndex()].addressPrefix]"
},
"copy":{
"name":"subnetcopy",
"count":"[parameters('noofsubnets')]"
}
}
]
}