Skip to content

Commit 5e8e7e6

Browse files
committed
Fix PR with suggestions from GitHub Copilot
Modified compute gallery check
1 parent ccebe80 commit 5e8e7e6

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

helpers/GenerateResourcesAndImage.ps1

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ Function GenerateResourcesAndImage {
9292
.PARAMETER ManagedImageName
9393
The name of the managed image to create. The default is "Runner-Image-{{ImageType}}".
9494
.PARAMETER ComputeGalleryName
95-
The name of the compute gallery to create. If specified will override the default behavior of creating a managed image.
96-
Will use the ResourceGroupName parameter as the resource group for the compute gallery.
95+
The name of the existing compute gallery to use. If specified, the image definition and version will be created in this gallery instead of creating a managed image.
96+
The compute gallery must already exist in the resource group specified by the ResourceGroupName parameter.
9797
.PARAMETER ComputeGalleryImageName
98-
The name of the compute gallery image to create. This is required if ComputeGalleryName is specified.
98+
The name of the compute gallery image definition to create within the specified compute gallery. This is required if ComputeGalleryName is specified.
9999
.PARAMETER ComputeGalleryImageVersion
100-
The name of the compute gallery image version to create. This is required if ComputeGalleryName is specified.
100+
The name of the compute gallery image version to create within the specified compute gallery image definition. This is required if ComputeGalleryName is specified.
101101
.PARAMETER AzureLocation
102102
The Azure location where the Azure resources will be created. For example: "East US"
103103
.PARAMETER ImageGenerationRepositoryRoot
@@ -299,15 +299,23 @@ Function GenerateResourcesAndImage {
299299
throw "Resource group '$ResourceGroupName' does not exist."
300300
}
301301

302-
# Check compute gallery existence
302+
# Check compute gallery and image definition existence
303303
if ($ComputeGalleryName) {
304-
$ComputeGalleryExists = [System.Convert]::ToBoolean((az sig show --resource-group $ResourceGroupName --gallery-name $ComputeGalleryName --name $ComputeGalleryImageName --query "id" --output tsv 2>$null));
304+
$ComputeGalleryExists = az sig show --resource-group $ResourceGroupName --gallery-name $ComputeGalleryName --query "id" --output tsv 2>$null;
305305
if ($ComputeGalleryExists) {
306306
Write-Verbose "Compute gallery '$ComputeGalleryName' already exists in resource group '$ResourceGroupName'."
307307
}
308308
else {
309309
throw "Compute gallery '$ComputeGalleryName' does not exist in resource group '$ResourceGroupName'."
310310
}
311+
312+
$ImageDefinitionExists = az sig image-definition show --resource-group $ResourceGroupName --gallery-name $ComputeGalleryName --name $ComputeGalleryImageName --query "id" --output tsv 2>$null;
313+
if ($ImageDefinitionExists) {
314+
Write-Verbose "Compute gallery image definition '$ComputeGalleryImageName' already exists in compute gallery '$ComputeGalleryName'."
315+
}
316+
else {
317+
throw "Compute gallery image definition '$ComputeGalleryImageName' does not exist in compute gallery '$ComputeGalleryName'."
318+
}
311319
}
312320

313321
# Create service principal

0 commit comments

Comments
 (0)