Azure: ARM – incorrect segment lengths

Автор: | 21/03/2017

Во время деплоя группы ресурсов – Azure Resource Manager сообщает об ошибке:

# azure group create -l westeurope -n jm-website-sw-custom-1 -f jm-website-sw-custom-domain.json -e jm-website-sw.parameters.json
info:    Executing command group create
+ Getting resource group jm-website-sw-custom-1                                
+ Updating resource group jm-website-sw-custom-1                               
info:    Updated resource group jm-website-sw-custom-1
+ Initializing template configurations and parameters                          
+ Creating a deployment                                                        
error:   InvalidTemplate : Deployment template validation failed: 'The template resource 'jm-website-sw-custom-1-cdn-profile/jm-website-sw-custom-1-cdn-endpointcustom-name' for type 'Microsoft.Cdn/profiles/endpoints/customdomains' at line '1' and column '16113' 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. Please see https://aka.ms/arm-template/#resources for usage details.'.
error:   Deployment validate failed.

The template resource […] for type ‘Microsoft.Cdn/profiles/endpoints/customdomains’ […] 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.

Звучит достаточно бредово.

Ресурс выглядит так:

...
    {
      "type": "Microsoft.Cdn/profiles/endpoints/customdomains",
      "name": "[variables('CDNCustomDomainName')]",
      "apiVersion": "2016-04-02",
      "properties": {
        "hostName": "[parameters('envDNSfqdn')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cdn/profiles', variables('CDNprofileName'))]"
      ]
    }
...

“name” раскрывается ARM-ом как jm-website-sw-custom-1-cdn-profile/jm-website-sw-custom-1-cdn-endpointcustom-name, т .е. содержит два элемента.

Теперь посмотрим на “родительский” ресурс:

...
    {
      "apiVersion": "2015-06-01",
      "dependsOn": [
        "[concat('Microsoft.Cdn/profiles/', variables('CDNprofileName'))]"
      ],
      "location": "[resourceGroup().location]",
      "name": "[concat(variables('CDNprofileName'),'/', variables('CDNendpointName'))]",
      "type": "Microsoft.Cdn/profiles/endpoints",
      "properties": {
        "originHostHeader": "[parameters('envDNSfqdn')]",
        "isHttpAllowed": true,
        "isHttpsAllowed": true,
        "origins": [
          {
            "name": "[parameters('envDNSfqdn')]",
            "properties": {
              "hostName": "[parameters('envDNSfqdn')]"
            }
          }
        ]
      }
    },
...

У родителя:

“name”: “[concat(variables(‘CDNprofileName’),’/’, variables(‘CDNendpointName’))]”,
“type”: “Microsoft.Cdn/profiles/endpoints”,

У потомка (или “вложенного ресурса”):

“type”: “Microsoft.Cdn/profiles/endpoints/customdomains”,
“name”: “[variables(‘CDNCustomDomainName’)]”,

Меняем имя ресурса Microsoft.Cdn/profiles/endpoints/customdomains – добавляем один элемент:

...
"name": "[concat(variables('CDNprofileName'),'/', variables('CDNendpointName'), '/customdomain')]",
...

Готово.

Выносим в переменную, ещё раз обновляем, запускаем:

...
"CDNCustomDomainName": "[concat(variables('CDNprofileName'),'/', variables('CDNendpointName'), '/customdomain')]"
...
    {
      "type": "Microsoft.Cdn/profiles/endpoints/customdomains",
      "name": "[variables('CDNCustomDomainName')]",
...

Маразм какой-то.

Решение нагуглено тут>>> и тут>>>.