Azure网站资源模板错误 [英] Azure website resource template error
问题描述
我正在尝试使用 AzureResourceManager PowerShell模块以创建和配置网站.我从Visual Studio生成的模板文件开始,当我通过New-AzureResourceGroup -TemplateFile website.json
使用它时,该文件工作正常.
I'm attempting to use the AzureResourceManager PowerShell module to create and configure a website. I started with a template file generated by Visual Studio, which works fine when I use it via New-AzureResourceGroup -TemplateFile website.json
.
因此,现在我正在尝试调整模板文件以配置站点.我正在尝试设置php和.NET Framework版本.根据模式,这些属性是通过资源数组中的一个配置对象.
So now I'm trying to tweak the template file to configure the site. I'm trying to set the php and .NET Framework versions. According to the schema these properties are set via a config object in a resources array.
这是我的json模板的网站部分.我添加了资源"部分:
Here's the website section of my json template. The "resources" section is what I added:
{
"apiVersion": "2014-06-01",
"name": "[parameters('siteName')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('siteLocation')]",
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource"
},
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
],
"properties": {
"name": "[parameters('siteName')]",
"serverFarm": "[parameters('hostingPlanName')]"
},
"resources": [
{
"apiVersion": "2014-04-01",
"type": "Microsoft.Web/sites/config",
"name": "config",
"properties": {
"name": "config",
"phpVersion": "",
"netFrameworkVersion": "V4.5"
}
}
]
},
当我将此模板传递给Test-AzureResourceGroupTemplate
时,出现此错误:
When I pass this template to Test-AzureResourceGroupTemplate
I get this error:
Code : InvalidTemplate
Message : Deployment template validation failed: 'The template resource 'config' for type 'Microsoft.Web/sites/config' has
incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root
resource type must have segment length one greater than its resource name'.
我找不到与此相关的任何文档.有人知道这个错误是什么意思,或者我做错了什么?
I can't find any documentation on this. Does anyone know what this error means, or what I'm doing wrong?
推荐答案
只要写出问题,我就能找出答案.
Never fails, as soon as I write out the question I figure out the answer.
该错误意味着由于这是一个嵌套资源(配置对象嵌套在站点对象内部),因此名称需要反映出来.因此,其名称应类似于mysite/config
,而不是config
.我还需要添加dependsOn
部分.这是成功验证的模板:
The error means that because this is a nested resource (the config object is nested inside the site object) the name needs to reflect this. So instead of config
the name should be something like mysite/config
. I also needed to add the dependsOn
section. Here's the template that validated successfully:
"resources": [
{
"apiVersion": "2014-04-01",
"type": "Microsoft.Web/sites/config",
"name": "[concat(parameters('siteName'), '/config')]",
"dependsOn": [
"[concat('Microsoft.Web/sites/', parameters('siteName'))]"
],
"properties": {
"phpVersion": "",
"netFrameworkVersion": "V4.5"
}
}
]
这篇关于Azure网站资源模板错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!