hybrid worker extension installation error

Yim, Sam 126 Reputation points
2023-01-25T20:29:16.8433333+00:00

I'm trying to install the hybrid worker extension to my azure vm running on windows. I can get it to work when the automation account is in the same resource group as the virtual machine, but I need to hook up the extension to an automation account that is in a different resource group. I try to add the variables('secondGroup') in the AutomationAccountUrl at the very bottom to specify a different resource group.

This is the error I get:

User's image

This is the code I have:


{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "environmentVariables": {
      "type": "secureObject"
    },
    "vmName": {
      "type": "string"
    },
    "automationAccount": {
      "type": "string"
    },
    "monitorAutomationAccountResourceId": {
      "type": "string"
    }
  },
  "variables": {
    "secondGroup": "testresourcegroup"
  },
  "resources": [
    {
      "type": "Microsoft.Automation/automationAccounts",
      "apiVersion": "2021-06-22",
      "name": "[parameters('automationAccount')]",
      "location": "usgovvirginia",
      "properties": {
        "sku": {
          "name": "Basic"
        }
      },
      "resources": [
        {
          "name": "NewHybridGroup",
          "type": "hybridRunbookWorkerGroups",
          "apiVersion": "2022-02-22",
          "dependsOn": [
            "[resourceId('Microsoft.Automation/automationAccounts', parameters('automationAccount'))]"
          ],
          "resources" : [
            {
              "name": "[guid('testhw', parameters('vmName'))]",
              "type": "hybridRunbookWorkers",
              "apiVersion": "2021-06-22",
              "dependsOn": [
                "[resourceId('Microsoft.Automation/automationAccounts/hybridRunbookWorkerGroups', parameters('automationAccount'), 'NewHybridGroup')]"
              ],
              "properties": {
                "vmResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
              }
            }
          ]
        }
      ]
    },
    {
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "name": "[concat(parameters('vmName'),'/HybridWorkerExtension')]",
      "apiVersion": "2022-03-01",
      "location": "USDoD East",
      "properties": {
        "publisher": "Microsoft.Azure.Automation.HybridWorker",
        "type": "HybridWorkerForWindows",
        "typeHandlerVersion": "1.1",
        "autoUpgradeMinorVersion": true,
        "enableAutomaticUpgrade": true,
        "settings": {
          "AutomationAccountURL": "[reference(resourceId(variables('secondGroup'), 'Microsoft.Automation/automationAccounts', parameters('automationAccount'))).AutomationHybridServiceUrl]"
        }
      }
    }
  ],
  "outputs": {
  }
}


}
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,111 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 17,321 Reputation points
    2023-02-03T17:21:26.5233333+00:00

    You can deploy to more than one resource group in a single ARM template. To target a resource group that is different than the one for parent template, use a nested or linked template. Within the deployment resource type, specify values for resource group that you want the nested template to deploy to.

    Here is sample ARM template for HWG for reference.

    {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "vmName": {
          "type": "string"
        },
        "automationAccount": {
          "type": "string"
        },
        "secondResourceGroup":{
          "type": "string",
          "metadata": {
            "description": "description"
          }
        }
      },
      "variables": {
      },
      "resources": [
        {
          "type": "Microsoft.Automation/automationAccounts",
          "apiVersion": "2021-06-22",
          "name": "[parameters('automationAccount')]",
          "location": "eastus",
          "properties": {
            "sku": {
              "name": "Basic"
            }
          },
          "resources": [
            {
              "name": "NewHybridGroup",
              "type": "hybridRunbookWorkerGroups",
              "apiVersion": "2022-02-22",
              "dependsOn": [
                "[resourceId('Microsoft.Automation/automationAccounts', parameters('automationAccount'))]"
              ],
              "resources": [
                {
                  "name": "[guid('testhw',parameters('vmName'))]",
                  "type": "hybridRunbookWorkers",
                  "apiVersion": "2021-06-22",
                  "dependsOn": [
                    "[resourceId('Microsoft.Automation/automationAccounts/hybridRunbookWorkerGroups',parameters('automationAccount'),'NewHybridGroup')]"
                  ],
                  "properties": {
                    "vmResourceId": "[resourceId('Microsoft.Compute/virtualMachines',parameters('vmName'))]"
                  }
                }
              ]
            }
          ]
        },
        {
          "type": "Microsoft.Resources/deployments",
          "apiVersion": "2021-04-01",
          "name": "nestedTemplate",
          "resourceGroup": "[parameters('secondResourceGroup')]",
          "properties": {
            "mode": "Incremental",
            "template": {
              "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
              "contentVersion": "1.0.0.0",
              "parameters": {},
              "variables": {},
              "resources": [
                {
                  "type": "Microsoft.Compute/virtualMachines/extensions",
                  "name": "[concat(parameters('vmName'),'/', 'HybridWorkerExtension')]",
                  "apiVersion": "2022-08-01",
                  "location": "westus2",
                  "properties": {
                    "publisher": "Microsoft.Azure.Automation.HybridWorker",
                    "type": "HybridWorkerForWindows",
                    "typeHandlerVersion": "1.1",
                    "autoUpgradeMinorVersion": true,
                    "enableAutomaticUpgrade": true,
                    "settings": {
                      "AutomationAccountURL": "[reference(resourceId('Microsoft.Automation/automationAccounts',parameters('automationAccount'))).AutomationHybridServiceUrl]"
                    }
                  }
                }
              ]
            },
            "parameters": {}
          }
        }
    
      ],
      "outputs": {
      }
    }
    
    
    0 comments No comments