0
votes

My ARM template code fails with the following validation error. enter image description here

The Domain join should wait until the custom script extension is complete. Kindly please see code below. I can't get my head around how the resource and subresource dependency work and how to name the resource. Appreciate if you can guide me to an article to learn.

   {
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "name": "[concat(variables('varnodeNamePrefix'),copyindex(1),'/cse')]",
    "apiVersion": "2017-03-30",
    "location": "[variables('varlocation')]",
    "dependsOn": [
      "[concat(variables('varnodeNamePrefix'),copyindex(1))]"
    ],
    "properties": {
      "publisher": "Microsoft.Compute",
      "type": "CustomScriptExtension",
      "typeHandlerVersion": "1.8",
      "autoUpgradeMinorVersion": true,
      "settings": {
        "fileUris": [
          "https://XXXXXXXXXXX.blob.core.windows.net/powershelscripts/sqlcluster/InstallAdditionalModules.ps1"
        ]
      },
      "protectedSettings": {
        "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted ./sqlcluster/InstallAdditionalModules.ps1",
        "storageAccountName": "sdfsdfsdfsdf",
        "storageAccountKey": "sdsdfsdf/BH9C+fdgdfgdfgdfg+fgdfgdfg=="
      }
    },
    "copy": {
      "name": "WinFeatures",
      "count":"[variables('varvmCount')]"
    }
 },

 {
  "apiVersion": "2015-06-15",
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "name": "[concat(variables('varnodeNamePrefix'),copyindex(1),'/joindomain')]",
  "location": "[resourceGroup().location]",
  "dependsOn": ["[concat(variables('varnodeNamePrefix'),copyindex(1),'/cse')]"            
               ],
  "properties": {
    "publisher": "Microsoft.Compute",
    "type": "JsonADDomainExtension",
    "typeHandlerVersion": "1.3",
    "autoUpgradeMinorVersion": true,
    "settings": {
      "Name": "[variables('vardomainToJoin')]",
      "User": "[concat(variables('vardomainToJoin'), '\\', variables('vardomainUsername'))]",
      "Restart": "true",
      "Options": "[variables('vardomainJoinOptions')]"
    },
    "protectedSettings": {
      "Password": "[variables('vardomainPassword')]"
    }
  },
  "copy": {
    "name": "joindomain",
    "count":"[variables('varvmCount')]"
  }
1

1 Answers

1
votes

resourceId is wrong, should be this:

"[resourceId('Microsoft.Compute/virtualMachines/extensions',concat(variables('varnodeNamePrefix'),copyindex(1)),'extensions')]"

or simply:

concat(variables('varnodeNamePrefix'),copyindex(1),'/extensions')

what the error tells you - you have 3 segments here: Microsoft.Compute/virtualMachines/extensions, but only 1 after that: concat(variables('varnodeNamePrefix'),copyindex(1),'/extensions')).

But it should have 2 segments because its trying to do this:

Microsoft.Compute/virtualMachines/{segment1}/extensions/{segment2}

Working repro:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "variables": {
        "varnodeNamePrefix": "testing"
    },
    "resources": [
        {
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "name": "[concat(variables('varnodeNamePrefix'),copyindex(1),'/cse')]",
            "apiVersion": "2017-03-30",
            "location": "[resourceGroup().location]",
            "properties": {
                "publisher": "Microsoft.Compute",
                "type": "CustomScriptExtension",
                "typeHandlerVersion": "1.8",
                "autoUpgradeMinorVersion": true,
                "settings": {
                    "fileUris": [
                        "https://XXXXXXXXXXX.blob.core.windows.net/powershelscripts/sqlcluster/InstallAdditionalModules.ps1"
                    ]
                },
                "protectedSettings": {
                    "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted ./sqlcluster/InstallAdditionalModules.ps1",
                    "storageAccountName": "sdfsdfsdfsdf",
                    "storageAccountKey": "sdsdfsdf/BH9C+fdgdfgdfgdfg+fgdfgdfg=="
                }
            },
            "copy": {
                "name": "WinFeatures",
                "count": 3
            }
        },
        {
            "apiVersion": "2015-06-15",
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "name": "[concat(variables('varnodeNamePrefix'),copyindex(1),'/joindomain')]",
            "location": "[resourceGroup().location]",
            "dependsOn": [
                "[resourceId('Microsoft.Compute/virtualMachines/extensions',concat(variables('varnodeNamePrefix'),copyindex(1)),'cse')]"
            ],
            "properties": {
                "publisher": "Microsoft.Compute",
                "type": "JsonADDomainExtension",
                "typeHandlerVersion": "1.3",
                "autoUpgradeMinorVersion": true,
                "settings": {
                    "Name": "yyy.zzz",
                    "User": "[concat('xxx', '\\', 'xxx')]",
                    "Restart": "true"
                },
                "protectedSettings": {
                    "Password": "xxx"
                }
            },
            "copy": {
                "name": "joindomain",
                "count": 3
            }
        }
    ]
}

full working example: https://paste.ee/p/XlBHY (basically its the same as the one written above)