我试图使用AzureResourceManager PowerShell模块来创建和配置一个网站。我从Visual生成的模板文件开始,当我通过New-AzureResourceGroup -TemplateFile website.json使用它时,它工作得很好。
因此,现在我试图调整模板文件来配置站点。我正在尝试设置php和.NET框架版本。根据模式,这些属性是通过资源数组中的配置对象来设置的。
这是我的json模板的网站部分。“资源”一节是我补充的内容:
{
"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时,我会得到以下错误:
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'.我找不到这方面的任何文件。有人知道这个错误意味着什么吗,或者我做错了什么?
发布于 2014-11-05 21:13:10
只要我写出问题,我就会想出答案。
这个错误意味着,因为这是一个嵌套的资源( config对象嵌套在站点对象中),所以名称需要反映这一点。所以,这个名字应该是类似于config的,而不是mysite/config。我还需要添加dependsOn部分。下面是成功验证的模板:
"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"
}
}
]发布于 2019-03-20 21:57:01
我碰到了同样的问题,其他的答案对我来说都没有用,结果发现这比其他答案所显示的要稍微多一点。首先,对于根级资源,文档指定必须:
...have名称中的分段比资源类型中的少一个
换句话说,如果您要创建一个:
"type": "Microsoft.Web/sites"然后,由于名称必须比类型少一个段,因此在本例中只能使用单个段来表示名称,即:
"name": "MySite"对于嵌套资源,规则是:
类型和名称具有相同数量的段数。
但是,这假定您正在缩短嵌套资源的类型,例如,将"Microsoft.Web/sites/config“类型创建为"Microsoft.Web/sites”类型的父级内的嵌套资源,并指定嵌套资源:
"type": "config"因此,这里您也只能指定单个段名,例如:
"name": "MyConfig"所以把这一切加在一起:
{
"type": "Microsoft.Web/sites",
"name": "MySite",
"various other properties": ...,
"resources": [
{
"type": "config",
"name": "MyConfig"
"various other properties": ...
}
]
}另一方面,如果您在嵌套资源中指定了完整的类型名称(如接受的答案中所示),则需要诉诸根命名约定,即名称中的分段比类型少一个!将上面的内容转换为:
{
"type": "Microsoft.Web/sites",
"name": "MySite",
"various other properties": ...,
"resources": [
{
"type": "Microsoft.Web/sites/config",
"name": "MySite/MyConfig"
"various other properties": ...
}
]
}发布于 2018-04-11 10:29:54
对于非英语母语的人来说,“不正确的段长”错误消息很难理解,所以用简单的英语/json来解释:例如,您有一个类型为Microsoft.Network/trafficManagerProfiles资源的资源,并且出于某种原因,您需要将具有类型Microsoft.Network/trafficManagerProfiles/ExternalEndpoints的嵌套资源定义为一个单独的资源。
嵌套资源必须具有名称parent_resource_name/nested_res_name。
正确的(简化)模式是:
{
"type": "Microsoft.Network/trafficManagerProfiles",
"name": "[variables('trafManagerProfileName')]",
...
},
{
"type": "Microsoft.Network/trafficManagerProfiles/ExternalEndpoints",
"name": "[concat(variables('trafManagerProfileName'), '/Endpoint', copyIndex())]",
"dependsOn": [
"[concat('Microsoft.Network/trafficManagerProfiles/', variables('trafManagerProfileName'))]",
"[parameters('app_name')]" # where the endpoint should look at
],
...
}附注:如果您需要根据第三个资源的计数动态生成嵌套资源:如何在ARM模板中动态生成流量管理器端点?,您可能也会对这个问题感兴趣。
https://stackoverflow.com/questions/26766882
复制相似问题