@@ -195,7 +195,7 @@ function Test-Gallery
195
195
- PurchasePlanPublisher $purchasePlanPublisher ;
196
196
197
197
$wildcardNameQuery = ($galleryImageName -replace " .$" ) + " *"
198
- $galleryImageDefinitionList = Get-AzGalleryImageDefinition - ResourceGroupName $rgname - GalleryName $galleryName - Name $wildcardNameQuery ;
198
+ $galleryImageDefinitionList = Get-AzGalleryImageDefinition - ResourceGroupName $rgname - GalleryName $galleryName - Name $wildcardNameQuery ;
199
199
$definition = $galleryImageDefinitionList | ? {$_.Name -eq $galleryImageName };
200
200
Verify- GalleryImageDefinition $definition $rgname $galleryImageName $loc $description1 `
201
201
$eula $privacyStatementUri $releaseNoteUri `
@@ -344,3 +344,61 @@ function Test-Gallery
344
344
Clean - ResourceGroup $rgname
345
345
}
346
346
}
347
+
348
+ <#
349
+ . SYNOPSIS
350
+ Testing creating VM with a shared gallery image from a different subscription.
351
+ #>
352
+ function Test-GalleryCrossTenant
353
+ {
354
+ # Setup
355
+ # In order to record this test, please use another subscription to create a gallery image and share the image to the test subscription. And then set the gallery image id here.
356
+ $imageId = " /subscriptions/97f78232-382b-46a7-8a72-964d692c4f3f/resourceGroups/xwRg/providers/Microsoft.Compute/galleries/galleryForCirrus/images/xwGalleryImageForCirrusWindows/versions/1.0.0" ;
357
+
358
+ $rgname = Get-ComputeTestResourceName ;
359
+
360
+ try
361
+ {
362
+ # Common
363
+ $loc = Get-ComputeVMLocation ;
364
+ New-AzResourceGroup - Name $rgname - Location $loc - Force;
365
+
366
+ # Create a VM first
367
+ $vmsize = ' Standard_D2_v2' ;
368
+ $vmname = ' vm' + $rgname ;
369
+ $p = New-AzVMConfig - VMName $vmname - VMSize $vmsize ;
370
+
371
+ # NRP
372
+ $subnet = New-AzVirtualNetworkSubnetConfig - Name (' subnet' + $rgname ) - AddressPrefix " 10.0.0.0/24" ;
373
+ $vnet = New-AzVirtualNetwork - Force - Name (' vnet' + $rgname ) - ResourceGroupName $rgname - Location $loc - AddressPrefix " 10.0.0.0/16" - Subnet $subnet ;
374
+ $vnet = Get-AzVirtualNetwork - Name (' vnet' + $rgname ) - ResourceGroupName $rgname ;
375
+ $subnetId = $vnet.Subnets [0 ].Id;
376
+ $pubip = New-AzPublicIpAddress - Force - Name (' pubip' + $rgname ) - ResourceGroupName $rgname - Location $loc - AllocationMethod Dynamic - DomainNameLabel (' pubip' + $rgname );
377
+ $pubip = Get-AzPublicIpAddress - Name (' pubip' + $rgname ) - ResourceGroupName $rgname ;
378
+ $nic = New-AzNetworkInterface - Force - Name (' nic' + $rgname ) - ResourceGroupName $rgname - Location $loc - SubnetId $subnetId - PublicIpAddressId $pubip.Id ;
379
+ $nic = Get-AzNetworkInterface - Name (' nic' + $rgname ) - ResourceGroupName $rgname ;
380
+ $nicId = $nic.Id ;
381
+ $p = Add-AzVMNetworkInterface - VM $p - Id $nicId - Primary;
382
+
383
+ # OS & Image
384
+ $user = " Foo12" ;
385
+ $password = $PLACEHOLDER ;
386
+ $securePassword = ConvertTo-SecureString $password - AsPlainText - Force;
387
+ $cred = New-Object System.Management.Automation.PSCredential ($user , $securePassword );
388
+ $computerName = ' test' ;
389
+ $p = Set-AzVMOperatingSystem - VM $p - Windows - ComputerName $computerName - Credential $cred ;
390
+
391
+ $p = Set-AzVMSourceImage - VM $p - Id $imageId ;
392
+
393
+ # Virtual Machine
394
+ New-AzVM - ResourceGroupName $rgname - Location $loc - VM $p ;
395
+
396
+ $vm = Get-AzVM - ResourceGroupName $rgname - Name $vmname ;
397
+ Assert-AreEqual $imageId $vm.StorageProfile.ImageReference.Id ;
398
+ }
399
+ finally
400
+ {
401
+ # Cleanup
402
+ Clean - ResourceGroup $rgname
403
+ }
404
+ }
0 commit comments