azure-powershell
azure-powershell copied to clipboard
Update NewAzureVMCommand.cs
Description
Adding validation for SharedGalleryImageId and CommunityGalleryImageId in New-AzVM cmdlet
Mandatory Checklist
-
Please choose the target release of Azure PowerShell
- [X] General release
- [ ] Public preview
- [ ] Private preview
- [ ] Engineering build
- [ ] N/A
-
[X] Check this box to confirm: I have read the Submitting Changes section of
CONTRIBUTING.mdand reviewed the following information:
- SHOULD update
ChangeLog.mdfile(s) appropriately- For SDK-based development mode, update
src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.- A snippet outlining the change(s) made in the PR should be written under the
## Upcoming Releaseheader in the past tense.
- A snippet outlining the change(s) made in the PR should be written under the
- For autorest-based development mode, include the changelog in the PR description.
- Should not change
ChangeLog.mdif no new release is required, such as fixing test case only.
- For SDK-based development mode, update
- SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
- SHOULD have proper test coverage for changes in pull request.
- SHOULD NOT adjust version of module manually in pull request
️✔️Az.Accounts
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Az.Compute
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Breaking Change Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Signature Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Help File Existence Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️File Change Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️UX Metadata Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Test
️✔️ - Linux
️✔️ - MacOS
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Az.KeyVault
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Az.ManagedServiceIdentity
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Az.Monitor
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Az.Network
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Test
️✔️ - Linux
️✔️ - MacOS
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Az.OperationalInsights
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Az.PrivateDns
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
⚠️Az.RecoveryServices
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
⚠️Test
⚠️ - Linux
Type Title Current Coverage Last Coverage Description ⚠️ Test Coverage Less Than 80% 62.50 % 66.67% Test coverage cannot be lower than the number of the last release. ⚠️ - MacOS
Type Title Current Coverage Last Coverage Description ⚠️ Test Coverage Less Than 80% 62.50% 66.67% Test coverage cannot be lower than the number of the last release. ⚠️PowerShell Core - Windows
Type Title Current Coverage Last Coverage Description ⚠️ Test Coverage Less Than 80% 62.50% 66.67% Test coverage cannot be lower than the number of the last release. ⚠️Windows PowerShell - Windows
Type Title Current Coverage Last Coverage Description ⚠️ Test Coverage Less Than 80% 62.50% 66.67% Test coverage cannot be lower than the number of the last release.
️✔️Az.Security
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Test
️✔️ - Linux
️✔️ - MacOS
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Az.Sql
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Az.Ssh
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Test
️✔️ - Linux
️✔️ - MacOS
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Az.Storage
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
@microsoft-github-policy-service agree
More context to this PR.
Before this PR:
> $VmConfig = New-AzVMConfig -VMName testvm -VMSize Standard_B2s -SharedGalleryImageId /SharedGalleries/<subscription>-<gallery>/Images/<definition/Versions/<version> -Location WestUS2
Write-Output $VmConfig.StorageProfile.ImageReference
Publisher :
Offer :
Sku :
Version :
ExactVersion :
SharedGalleryImageId : /SharedGalleries/<sub>-<gallery>/Images/<definition/Versions/<version>
CommunityGalleryImageId :
Id :
# And then launching a Virtual Machine
> New-AzVM -VM $VmConfig -ResourceGroupName $ResourceGroupName -Location $VmRegion
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Azure.Commands.Compute.NewAzureVMCommand.retrieveImageVersion(String publisher, String offer, String sku, String version)
at Microsoft.Azure.Commands.Compute.NewAzureVMCommand.retrieveSpecificImageFromNotId()
at Microsoft.Azure.Commands.Compute.NewAzureVMCommand.DefaultExecuteCmdlet()
at Microsoft.Azure.Commands.Compute.NewAzureVMCommand.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
System.Management.Automation.InvocationInfo
Now, after this PR:
$VmConfig = New-AzVMConfig -VMName testvm -VMSize Standard_B2s -SharedGalleryImageId /SharedGalleries/<subscription>-<gallery>/Images/<definition/Versions/<version> -Location WestUS2
Write-Output $VmConfig.StorageProfile.ImageReference
Publisher :
Offer :
Sku :
Version :
ExactVersion :
SharedGalleryImageId : /SharedGalleries/<sub>-<gallery>/Images/<definition/Versions/<version>
CommunityGalleryImageId :
Id :
# And then launching a Virtual Machine
> New-AzVM -VM $VmConfig -ResourceGroupName $ResourceGroupName -Location $VmRegion
# Success!
@bilaakpan-ms @Sandido @haagha @grizzlytheodore Would you mind reviewing this simple PR ?
Up @bilaakpan-ms @Sandido @haagha @grizzlytheodore
@bilaakpan-ms @Sandido @haagha @grizzlytheodore up
/azp run azure-powershell - security-tools
Azure Pipelines successfully started running 1 pipeline(s).
Will look into this next week.
@Sandido have you had the chance to have a look by any chance ?
@mfortin , looking at this now, running some tests. In the future, and if you can now, share how you made the SharedGallery.
Hi @Sandido, yes absolutely. This specific gallery was created with the Direct Share feature https://learn.microsoft.com/en-ca/azure/virtual-machines/share-gallery-direct?tabs=portaldirect#prerequisites
az sig create \
--gallery-name myGallery \
--permissions groups \
--resource-group myResourceGroup
@mfortin do you expect the SharedGalleryImageId to be in this exact format as seen under the resource Properties? /SharedGalleries/-
This should work from any shared gallery, even if using the RBAC.
> Get-AzGalleryImageVersion -GalleryUniqueName $GalleryUniqueName -GalleryImageDefinitionName $GalleryImageDefinitionName -Location $Location -GalleryImageVersionName latest
Name : 2024.04.121845
Location : $Location
UniqueId : /SharedGalleries/<subscription uuid>-$GalleryUniqueName/Images/$GalleryImageDefinitionName/Versions/2024.04.121845
PublishedDate : 2024-04-12 6:45:07 PM
EndOfLifeDate : 2024-07-11 6:45:06 PM
It will always return the UniqueID as
/SharedGalleries/<subscription uuid>-<gallery name uppercase>/Images/<image definition name>/Versions/<version name>
PR is nearly ready for merge, just a couple of tweaks.
@sandido Updated as per your review.
/azp run azure-powershell - security-tools
Azure Pipelines successfully started running 1 pipeline(s).
/azp run azure-powershell - security-tools
Azure Pipelines successfully started running 1 pipeline(s).