What needs to change in the
resourceId('Microsoft.Compute/images/', parameters('imageName'))
command below in order to successfully retrieve theid
of an image resource that is located in a DIFFERENT resource group?
ERROR:
When we run an ARM template containing the following code, an error is returned which says that "The Image '/subscriptions/long-alpha-numeric-subscription-id/resourceGroups/myCurrentResourceGroup/providers/Microsoft.Compute/images/myimagename' cannot be found in 'westus' region.\ "
.
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2021-11-01",
"name": "[parameters('VmName')]",
"location": "[parameters('resourceGroupRegion')]",
"properties": {
"hardwareProfile": { "vmSize": "Standard_DS1_v2" },
"storageProfile": {
"imageReference": {
"id": "[resourceId('Microsoft.Compute/images/', parameters('imageName'))]"
},
...other stuff
WHAT WORKS:
However, when we replace the resourceId('Microsoft.Compute/images/', parameters('imageName'))
command with the explicit Id of the intended image from a DIFFERENT resource group in the same region that we cut and paste from the Azure Portal, the ARM template works fine.
So the image is visible to the process that runs the ARM template, but problem is in the syntax of the resourceId('Microsoft.Compute/images/', parameters('imageName'))
command.
WHAT WE NEED:
If you look carefully at the error message, it says that "The Image '/subscriptions/long-alpha-numeric-subscription-id/resourceGroups/myCurrentResourceGroup/providers/Microsoft.Compute/images/myimagename' cannot be found in 'westus' region.\"
The problem is that it is looking in myCurrentResourceGroup
, when the image is located in someOtherResourceGroup
within the same subscription.
What command needs to be entered into the ARM template in order for the ARM template to find the image from the DIFFERENT
someOtherResourceGroup
resource group without our needing to paste in the raw id value explicitly?
CodePudding user response:
You need to have someOtherResourceGroup
as a parameter and construct the id from there. Something like :
resourceId(parameters('someOtherResourceGroup'), 'Microsoft.Compute/images', parameters('imageName'))
See resourceId()
documentation. Notice that this someOtherResourceGroup
has to be in the same subscription, otherwise you have to pass the subscription ID in the same way.