Using a Shared Image Gallery from another tenant with an ARM template.

Meade, Mitch 1 Reputation point
2020-07-27T16:13:11.267+00:00

We are using ARM templates to deploy components to customer tenants, and we would like to utilize a Shared Image Gallery in our management tenant to deploy virtual machines to customer tenants. I have successfully created a Shared Image Gallery, built a test image and version, deployed the VM using CLI and PowerShell but I’ve been unsuccessful in building an ARM template to do the same. Since our deployment system is based on ARM templates, I need to fine a way to deploy a VM from a SIG to another tenant.

I have a test service principal in both tenants, and I authenticate with both tenant prior to deploying the ARM template. I know the security is correct as it’s successful using PowerShell or CLI.

The shared image gallery image is referenced from the ARM template:

    "storageProfile": {  
      "imageReference": {  
        "id": "/subscriptions/<sourceSubscriptionID>/resourceGroups/<sourceResourceGroupName>/providers/Microsoft.Compute/galleries/<sourceGalleryName>/images/<sourceImageName>/versions/<sourceVersion>"  
        },  

When I deploy this ARM template, the error message is as follows:

The client has permission to perform action 'Microsoft.Compute/galleries/images/versions/read' on scope '/subscriptions/<targetSubscriptionId>/resourcegroups/<targetResourceGroupName>/providers/Microsoft.Compute/virtualMachines/<newVMName>', however the current tenant <sourceTenantId> is not authorized to access linked subscription <sourceSubscriptionID>."

Is this possible with ARM? Has anyone seen samples on how to accomplish this by using ARM templates?

Most of my research is based on the MS article:

https://learn.microsoft.com/en-us/azure/virtual-machines/windows/share-images-across-tenants

Has anyone been successful deploying a SIG image through a ARM template?

Mitch

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,014 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. prmanhas-MSFT 17,946 Reputation points Microsoft Employee Moderator
    2020-07-28T11:45:35.873+00:00

    @MeadeMitch-4080 Thank you for your query.

    You will not be able to use the cross tenant reference in an ARM template. The reason for this is because there is no mechanism to authenticate against both tenants at once using your service principal in the ARM template.

    You may be able to set up something using an Azure function that runs on a timer to populate the images you want to share in your customer subscriptions.

    Do let me know if you have further queries regarding the same.

    Please 'Accept as answer' if it helped, so that it can help others in the community looking for help on similar topics


  2. Anonymous
    2020-10-17T00:19:14.073+00:00

    This should work using CLI az group deployment --aux-subs or --aux-tenants

    0 comments No comments

  3. Jayme Johnston 1 Reputation point
    2021-11-19T16:43:14.997+00:00

    I am having the same basic issue, but I am trying to do this via the the frontend UI (ARM managed-applications) combined with Bicep. I am trying to deploy a VM with the same storageProfile -> imageReference -> id reference as above. When it deploys it fails with the message (ref):

    Message: The client has permission to perform action 'Microsoft.Compute/galleries/images/versions/read' on scope <resourceID>, however the current tenant <tenantID> is not authorized to access linked subscription <subscriptionID>.
    Cause: The virtual machine or scale set was created through a gallery image in another tenant. You've tried to make a change to the virtual machine or scale set, but you don't have access to the subscription that owns the image.
    Workaround: Contact the owner of the subscription of the image version to grant read access to the image version.

    Is there any way to make this work using the ARM managed-applications Templates as a portal deployment? I briefly looked at using Scope to resource group or something similar, but I can't seem to make it work.

    Does anyone have any examples of ARM managed-applications combined with Bicep?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.