Changes to helper scripts to support ComputeGallery#13715
Changes to helper scripts to support ComputeGallery#13715Reterino wants to merge 2 commits intoactions:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the helpers/GenerateResourcesAndImage.ps1 helper to support producing images into an Azure Compute Gallery (Shared Image Gallery) instead of only producing managed images, aligning the helper’s CLI surface area with existing Packer template capabilities.
Changes:
- Adds
ComputeGalleryName,ComputeGalleryImageName, andComputeGalleryImageVersionparameters with basic validation (including a semver-style version check). - Introduces conditional artifact argument construction so Packer gets either managed image vars or compute gallery vars.
- Adds an Azure CLI check intended to validate compute gallery existence before running the Packer build.
| if ($ComputeGalleryName -and -not $ComputeGalleryImageVersion) { | ||
| throw "ComputeGalleryImageVersion parameter is required when ComputeGalleryName is specified." | ||
| } | ||
| if ($ComputeGalleryImageVersion -and -not ($ComputeGalleryImageVersion -match '^\d+\.\d+\.\d+$')) { |
There was a problem hiding this comment.
If ComputeGalleryImageName/ComputeGalleryImageVersion are provided without ComputeGalleryName, they are silently ignored and a managed image is produced. Add validation to reject "partial" compute gallery inputs (e.g., if either of the image name/version params are set, require ComputeGalleryName too) to prevent unexpected output artifacts.
| if ($ComputeGalleryImageVersion -and -not ($ComputeGalleryImageVersion -match '^\d+\.\d+\.\d+$')) { | |
| if ($ComputeGalleryImageName -and -not $ComputeGalleryName) { | |
| throw "ComputeGalleryName parameter is required when ComputeGalleryImageName is specified." | |
| } | |
| if ($ComputeGalleryImageVersion -and -not $ComputeGalleryName) { | |
| throw "ComputeGalleryName parameter is required when ComputeGalleryImageVersion is specified." | |
| } | |
| if ($ComputeGalleryName -and $ComputeGalleryImageVersion -and -not ($ComputeGalleryImageVersion -match '^\d+\.\d+\.\d+$')) { |
There was a problem hiding this comment.
If wanting to do complete validation rather than silently ignore, we could do a more comprehensive check of all scenarios using an array of the 3 inputs, select non-empty and then length -eq 0 or length -eq 3.
Not sure if this is worthwhile as it looks pretty messy, but may give extra validation for people mis-inputting the parameters.
Modified compute gallery check
e626c77 to
5e8e7e6
Compare
Description
This code slightly updates the helper script GenerateResourceAndImage.ps1 to add support for using a Compute Gallery. It modifies the input parameters to now accept ComputeGalleryName, ComputeGalleryImageName, ComputeGalleryImageVersion.
It adds logic to validate those parameters: if ComputeGalleryName exists, the other two must exist; and ComputeGalleryImageVersion must be semantic versioning notation.
It modifies the way artifact arguments are passed into the packer commands and uses an $artifactArgs array to do splatting and conditionally add either the managed image details or compute gallery details.
Related issue:
#13685
Check list
Tests are written(not applicable)Documentation is updated(not applicable)Other
This should still be backwards compatible for everyone currently using this helper script.
I was not sure if I should support both Managed Image and Compute Gallery at the same time, but I think that's fairly niche and there is still the option of environment variables for that.