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": {
}
}