Azure 网站资源模板错误 [英] Azure website resource template error

查看:16
本文介绍了Azure 网站资源模板错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

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.

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"
                }
            }
        ]
    },

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.

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屋!

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