Network Watcher ARM Template Fails to Deploy

58 views Asked by At

Trying to add an extension arm template to our Windows VM deployments, and noticed it is failing to validate the extension template. The Network Watcher Arm template fails to deploy with the below error message. Not sure what I could be missing here. I tried following the schema, found here.

ERROR TYPE Deployment template validation failed: 'The template resource 'networkWatcherAgent' for type 'Microsoft.Compute/virtualMachines/extensions' at line '24' and column '64' 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-syntax-resources for usage details.'. (Code: InvalidTemplate)

Arm template:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmName": {
            "type": "string"
        }
    },
    "variables": {
        "apiVersion": "2022-11-01"
    },
    "resources": [
        {
            "name": "networkWatcherAgent",
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "apiVersion": "[variables('apiVersion')]",
            "location": "[resourceGroup().location]",
            "dependsOn": [
                "[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"
            ],
            "properties": {
                "autoUpgradeMinorVersion": true,
                "publisher": "Microsoft.Azure.NetworkWatcher",
                "type": "NetworkWatcherAgentWindows",
                "typeHandlerVersion": "1.4"
            }
        }
    ]
}
1

There are 1 answers

2
Venkat V On

The Network Watcher Arm template fails to deploy with the below error message.

There might be a misunderstanding in the template structure; the dependency on Microsoft.Compute/virtualMachines might be causing issue.

enter image description here

Here is the updated ARM template to create a Network Watcher Agent extension in an existing Windows VM.

    {
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "vmName": {
                "type": "string"
            }
        },
        "variables": {
            "apiVersion": "2022-11-01"
        },
        "resources": [
            {
                "name": "[parameters('vmName')]",
                "type": "Microsoft.Compute/virtualMachines",
                "apiVersion": "2022-11-01",
                "location": "[resourceGroup().location]",
                "properties": {
                }
            },
            {
                "name": "[concat(parameters('vmName'), '/networkWatcherAgent')]",
                "type": "Microsoft.Compute/virtualMachines/extensions",
                "apiVersion": "[variables('apiVersion')]",
                "location": "[resourceGroup().location]",
                "dependsOn": [
                    "[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"
                ],
                "properties": {
                    "autoUpgradeMinorVersion": true,
                    "publisher": "Microsoft.Azure.NetworkWatcher",
                    "type": "NetworkWatcherAgentWindows",
                    "typeHandlerVersion": "1.4"
                }
            }
        ]
    }

Output

enter image description here