Create a shared image gallery with Azure PowerShell
A Shared Image Gallery simplifies custom image sharing across your organization. Custom images are like marketplace images, but you create them yourself. Custom images can be used to bootstrap deployment tasks like preloading applications, application configurations, and other OS configurations.
The Shared Image Gallery lets you share your custom VM images with others in your organization, within or across regions, within an AAD tenant. Choose which images you want to share, which regions you want to make them available in, and who you want to share them with. You can create multiple galleries so that you can logically group shared images.
The gallery is a top-level resource that provides full role-based access control (RBAC). Images can be versioned, and you can choose to replicate each image version to a different set of Azure regions. The gallery only works with Managed Images.
The Shared Image Gallery feature has multiple resource types.
|Image source||This is a resource that can be used to create an image version in an image gallery. An image source can be an existing Azure VM that is either generalized or specialized, a managed image, a snapshot, or an image version in another image gallery.|
|Image gallery||Like the Azure Marketplace, an image gallery is a repository for managing and sharing images, but you control who has access.|
|Image definition||Image definitions are created within a gallery and carry information about the image and requirements for using it internally. This includes whether the image is Windows or Linux, release notes, and minimum and maximum memory requirements. It is a definition of a type of image.|
|Image version||An image version is what you use to create a VM when using a gallery. You can have multiple versions of an image as needed for your environment. Like a managed image, when you use an image version to create a VM, the image version is used to create new disks for the VM. Image versions can be used multiple times.|
Create an image gallery
An image gallery is the primary resource used for enabling image sharing. Allowed characters for Gallery name are uppercase or lowercase letters, digits, dots, and periods. The gallery name cannot contain dashes. Gallery names must be unique within your subscription.
Create an image gallery using New-AzGallery. The following example creates a gallery named myGallery in the myGalleryRG resource group.
$resourceGroup = New-AzResourceGroup ` -Name 'myGalleryRG' ` -Location 'West Central US' $gallery = New-AzGallery ` -GalleryName 'myGallery' ` -ResourceGroupName $resourceGroup.ResourceGroupName ` -Location $resourceGroup.Location ` -Description 'Shared Image Gallery for my organization'
Share the gallery
We recommend that you share access at the image gallery level. Use an email address and the Get-AzADUser cmdlet to get the object ID for the user, then use New-AzRoleAssignment to give them access to the gallery. Replace the example email, email@example.com in this example, with your own information.
# Get the object ID for the user $user = Get-AzADUser -StartsWith firstname.lastname@example.org # Grant access to the user for our gallery New-AzRoleAssignment ` -ObjectId $user.Id ` -RoleDefinitionName Reader ` -ResourceName $gallery.Name ` -ResourceType Microsoft.Compute/galleries ` -ResourceGroupName $resourceGroup.ResourceGroupName
Azure Image Builder (preview) can help automate image version creation, you can even use it to update and create a new image version from an existing image version.
You can also create Shared Image Gallery resource using templates. There are several Azure Quickstart Templates available: