Azure ARM Template - accessing a resource Id created by one ARM template in another ARM template Azure ARM Template - accessing a resource Id created by one ARM template in another ARM template json json

Azure ARM Template - accessing a resource Id created by one ARM template in another ARM template


For this scenario where the storage account name is known and does not depend on the resource group (eg, uniqueString(resourceGroup().id)), then you can simply use the longer form for resourceId(). The full form looks like:

resourceId([subscriptionId], [resourceGroupName], resourceType, resourceName1, [resourceName2]...)

so we can optionally supply subscriptionId and resourceGroupName.

listKeys(resourceId(parameters('ResourceGroupAName'), 'Microsoft.Storage/storageAccounts', variables('ccPaymentStorageName'))

If it was in a different subscription, you could also specify the subscription.

listKeys(resourceId(parameters('SubscriptionId'), parameters('ResourceGroupAName'), 'Microsoft.Storage/storageAccounts', variables('ccPaymentStorageName'))

If your storage account name depends on the resource group like

"storageName": "[concat('mystorage', uniqueString(resourceGroup().id))]" // in Resource Group A

then you'll either need to always run the template that creates this account and output the storageName and the resourceGroup or find a way to reference the other resource group to get it's id so that the name can be re-created.

I have been able to use something like this to "re-create" the resource group id so I can generate the proper name of the storage account.

"otherResourceGroupId": "[concat(subscription().id, '/resourceGroups/', parameters('ResourceGroupName'))]"

Then I can use that to generate the name appropriately:

"storageAccountName": "[concat('mystorage', uniqueString(variables('otherResourceGroupId')))]"


You can try below(for an example ):-

"subNetId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('virtualNetworkNameRG'), '/providers/', 'Microsoft.Network/virtualNetworks/',parameters('virtualNetworkName'),'/subnets/', parameters('subnetName'))]",

refer https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions