Azure website resource template error Azure website resource template error powershell powershell

Azure website resource template error


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


I hit the same issue and neither of the other answers worked for me, turns out there's actually slightly more to this than the other answers show. Firstly, for a root level resource, the docs specify it must:

...have one less segment in the name than in the resource type

In other words if you're creating a:

"type": "Microsoft.Web/sites"

Then as the name must have one less segment than the type, we can only use a single segment for the name in this example, i.e. one:

"name": "MySite"

For a nested resource the rule is:

the type and name have the same number of segments

However this assumes that you are shortening a nested resource's type e.g. creating a type of "Microsoft.Web/sites/config" as a nested resource within a parent of type "Microsoft.Web/sites" and for the nested resource specifying:

"type": "config"

So here you can also only specify a single segment name, e.g.:

"name": "MyConfig"

So putting that all together you have:

{  "type": "Microsoft.Web/sites",  "name": "MySite",  "various other properties": ...,  "resources": [    {      "type": "config",      "name": "MyConfig"      "various other properties": ...    }  ]}

If on the other hand you specify the full type name in the nested resource (as shown in the accepted answer) you need to resort to the root naming convention of having one less segment in the name than the type! Converting the above you'd have:

{  "type": "Microsoft.Web/sites",  "name": "MySite",  "various other properties": ...,  "resources": [    {      "type": "Microsoft.Web/sites/config",      "name": "MySite/MyConfig"      "various other properties": ...    }  ]}


The 'incorrect segment lengths' error message is difficult to understand for non-English native so there's explanation in plain English/json:For example, you have a resource of type Microsoft.Network/trafficManagerProfiles resource and for some reason you need to define nested resource having type Microsoft.Network/trafficManagerProfiles/ExternalEndpoints as a separate resource.

The nested resource must have name parent_resource_name/nested_res_name

The correct (simplified) schema is:

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

p.s. you might be interested in this question as well if you need to generate nested resources dynamically based on count of third resource: How do I dynamically generate Traffic Manager endpoints in an ARM template?