Azure website resource template error

BenV picture BenV · Nov 5, 2014 · Viewed 20k times · Source

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?

Answer

BenV picture BenV · Nov 5, 2014

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