resourceId function find resource in different resource group

116 views Asked by At

What needs to be changed in the ARM template below in order to successfully reference an Azure Machine Learning Workspace that exists in a different resource group referred to as otherRG?

The breaking code uses this example:

"[resourceId('otherResourceGroup', 'Microsoft.Storage/storageAccounts', 'examplestorage')]"    

From this documentation link

The command to invoke the ARM template is:

az deployment group create --name <deployment-name> --resource-group <new-resource-group-name> --template-file C:\\path\\to\\my-template.json --verbose  --parameters C:\\path\\to\\keys.json  

The error message is:

ERROR: {"code": "InvalidTemplate", "message": "Deployment template validation failed: 'The resource 'Microsoft.MachineLearningServices/workspaces/<workspace-id>' is not defined in the template. Please see https://aka.ms/arm-syntax for usage details.'.", "additionalInfo": [{"type": "TemplateViolation", "info": {"lineNumber": 0, "linePosition": 0, "path": ""}}]}

The ARM template that is breaking is:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "workspaceName": {
            "type": "string",
            "metadata": {"description": "Specifies name of workspace to create."}
        },
        "location": {
            "type": "string",
            "allowedValues": [ "eastus", "eastus2", "westus", "westus2" ],
            "metadata": {"description": "Specifies the location for all resources." }
        },
        "datastoreCount": {
            "type": "int",
            "defaultValue": 2,
            "metadata": {"description": "Specifies the number of datastores to be created."}
        },
        "storageAccountName": {
            "type": "string",
            "metadata": {"description": "The name for the storage account to created and associated with the workspace."    }
        },
        "containerName": {
            "type": "string",
            "metadata": {"description": "The container name."}
        },
        "otherRG": {
            "type": "string",
            "metadata": {"description": "The name for the resource group in which the foundation is deployed."}
        },
        "subscriptionId": {"type": "string"}
    },
    "resources": [
        {
            "type": "Microsoft.MachineLearningServices/workspaces/datastores",
            "name": "[concat(parameters('workspaceName'), '/', 'datastore', copyIndex())]",
            "apiVersion": "2020-05-01-preview",
            "location": "[parameters('location')]",
            "dependsOn": [ 
                "[resourceId(parameters('otherRG'), 'Microsoft.MachineLearningServices/workspaces', parameters('workspaceName'))]",
                
                "[resourceId(parameters('otherRG'), 'Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
            ],
            "copy": {
                "name": "datastoreCopy",
                "count": "[int(parameters('datastoreCount'))]"
            },
            "properties": {
                "DataStoreType": "blob",
                "AccountName": "[parameters('storageAccountName')]",
                "ContainerName": "[parameters('containerName')]",
                "AccountKey": "[listKeys(resourceId(parameters('otherRG') , 'Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value]"
            }
        }
    ]
}

  

The values for all of the variables have been validated as correct, including the following: deployment-name, new-resource-group-name, workspace-id , otherRG .

This template worked when we created the workspace in the same template in the same resource group. The problem originated when the template was changed to refer to a pre-existing workspace in a different resource group, as shown in the code in this OP.

The problem seems isolated to the syntax of the ARM template shown above.

The following block in particular seems to be what is breaking:

            "dependsOn": [ 
                "[resourceId(parameters('otherRG'), 'Microsoft.MachineLearningServices/workspaces', parameters('workspaceName'))]",
                
                "[resourceId(parameters('otherRG'), 'Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
            ],  
0

There are 0 answers