Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/GalleryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,12 @@ public void TestInVMAccessControlProfileVersion()
TestRunner.RunTestScript("Test-InVMAccessControlProfileVersion");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGalleryImageDefinitionUpdateFeature()
{
TestRunner.RunTestScript("Test-GalleryImageDefinitionUpdateFeature");
}

}
}
80 changes: 79 additions & 1 deletion src/Compute/Compute.Test/ScenarioTests/GalleryTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1224,4 +1224,82 @@ function Test-InVMAccessControlProfileVersion
# Cleanup
Clean-ResourceGroup $rgname;
}
}
}
Comment thread
audreyttt marked this conversation as resolved.

<#
.SYNOPSIS
Tests updating gallery image definition features with StartsAtVersion and AllowUpdateImage parameters
#>
function Test-GalleryImageDefinitionUpdateFeature
{
# Setup
$rgname = Get-ComputeTestResourceName;
$loc = Get-ComputeVMLocation;

try
{
$location = $loc;
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# Gallery variables
$galleryName = 'gl' + $rgname;
$definitionName = 'def' + $rgname;
$skuDetails = @{
Publisher = 'testpub'
Offer = 'testoffer'
Sku = 'testsku'
}
$osType = 'Windows'
$osState = 'Specialized'

# Create gallery
New-AzGallery -ResourceGroupName $rgname -Name $galleryName -Location $location;

# Create image definition with features including StartsAtVersion
$initialSecurityFeature = New-Object -TypeName Microsoft.Azure.Management.Compute.Models.GalleryImageFeature `
-Property @{Name = 'SecurityType'; Value = 'TrustedLaunch'; StartsAtVersion = '4.0.0'}
$initialDiskControllerFeature = New-Object -TypeName Microsoft.Azure.Management.Compute.Models.GalleryImageFeature `
-Property @{Name = 'DiskControllerTypes'; Value = 'SCSI'; StartsAtVersion = '4.0.0'}
$initialFeatures = @($initialSecurityFeature, $initialDiskControllerFeature);

New-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName `
-Name $definitionName -Location $location `
-Publisher $skuDetails.Publisher -Offer $skuDetails.Offer -Sku $skuDetails.Sku `
-OsState $osState -OsType $osType -Feature $initialFeatures -ErrorAction Stop;

$definition = Get-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName -Name $definitionName;
Assert-NotNull $definition;
Assert-AreEqual $definition.Name $definitionName;
Assert-AreEqual $definition.Features.Count 2;

# Update with AllowUpdateImage using different feature values
$securityFeature = New-Object -TypeName Microsoft.Azure.Management.Compute.Models.GalleryImageFeature `
-Property @{Name = 'SecurityType'; Value = 'TrustedLaunch'; StartsAtVersion = '4.0.0'}
$diskControllerFeature = New-Object -TypeName Microsoft.Azure.Management.Compute.Models.GalleryImageFeature `
-Property @{Name = 'DiskControllerTypes'; Value = 'SCSI, NVMe'; StartsAtVersion = '4.0.0'}
$features = @($securityFeature, $diskControllerFeature);

Update-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName `
-Name $definitionName -Feature $features -AllowUpdateImage $true;

# Verify the updated definition
$updatedDefinition = Get-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName -Name $definitionName;
Comment on lines +1283 to +1286
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test uses Update-AzGalleryImageDefinition and Get-AzGalleryImageDefinition without -ErrorAction Stop. In these scenario tests, non-terminating errors can lead to false positives or harder-to-diagnose failures later in the script. Consider adding -ErrorAction Stop (mandatory for reliability) to the update and subsequent get so the test fails at the real error site.

Suggested change
-Name $definitionName -Feature $features -AllowUpdateImage $true;
# Verify the updated definition
$updatedDefinition = Get-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName -Name $definitionName;
-Name $definitionName -Feature $features -AllowUpdateImage $true -ErrorAction Stop;
# Verify the updated definition
$updatedDefinition = Get-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName -Name $definitionName -ErrorAction Stop;

Copilot uses AI. Check for mistakes.
Assert-NotNull $updatedDefinition;
Assert-AreEqual $updatedDefinition.Features.Count 2;

$diskControllerUpdated = $updatedDefinition.Features | Where-Object { $_.Name -eq 'DiskControllerTypes' };
Assert-NotNull $diskControllerUpdated;
Assert-AreEqual $diskControllerUpdated.Value 'SCSI, NVMe';
Assert-AreEqual $diskControllerUpdated.StartsAtVersion '4.0.0';

$securityUpdated = $updatedDefinition.Features | Where-Object { $_.Name -eq 'SecurityType' };
Assert-NotNull $securityUpdated;
Assert-AreEqual $securityUpdated.Value 'TrustedLaunch';
Assert-AreEqual $securityUpdated.StartsAtVersion '4.0.0';
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname;
}
}

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

-->
## Upcoming Release
* Added `-Feature` parameter to `Update-AzGalleryImageDefinition` cmdlet to allow updating existing gallery image features (such as DiskControllerTypes, SecurityType, IsAcceleratedNetwork, and IsHibernate). Each feature supports a `StartsAtVersion` property to specify the minimum gallery image version that supports the updated feature.
* Added `-AllowUpdateImage` parameter to `Update-AzGalleryImageDefinition` cmdlet. Must be set to true when using the `-Feature` parameter to update gallery image features.

## Version 11.4.0
* Added `-DiskIOPSReadWrite` and `-DiskMBpsReadWrite` parameters to `Add-AzVMDataDisk` cmdlet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,20 @@ public override void ExecuteCmdlet()
galleryImage.PurchasePlan.Product = this.PurchasePlanProduct;
}

if (this.IsParameterBound(c => c.Feature))
{
galleryImage.Features = new List<GalleryImageFeature>();
for (int i = 0; i < this.Feature.Length; i++)
{
galleryImage.Features.Add(this.Feature[i]);
}
Comment on lines +526 to +530
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This manual copy loop is more verbose than necessary and makes the intent (assigning all provided features) less clear. Prefer constructing the list directly from the array (e.g., via ToList()), which reduces code and the chance of future off-by-one / null-handling issues. This is optional but would improve readability.

Suggested change
galleryImage.Features = new List<GalleryImageFeature>();
for (int i = 0; i < this.Feature.Length; i++)
{
galleryImage.Features.Add(this.Feature[i]);
}
galleryImage.Features = this.Feature.ToList();

Copilot uses AI. Check for mistakes.
}
Comment thread
audreyttt marked this conversation as resolved.

if (this.IsParameterBound(c => c.AllowUpdateImage))
{
galleryImage.AllowUpdateImage = this.AllowUpdateImage;
}
Comment thread
audreyttt marked this conversation as resolved.

var result = GalleryImagesClient.CreateOrUpdate(resourceGroupName, galleryName, galleryImageName, galleryImage);
var psObject = new PSGalleryImage();
ComputeAutomationAutoMapperProfile.Mapper.Map<GalleryImage, PSGalleryImage>(result, psObject);
Expand Down Expand Up @@ -639,5 +653,17 @@ public override void ExecuteCmdlet()
Mandatory = false,
ValueFromPipelineByPropertyName = true)]
public Hashtable Tag { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "A list of gallery image features to update. Each feature can include a StartsAtVersion property to indicate the minimum gallery image version that supports it.")]
public GalleryImageFeature[] Feature { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Must be set to true if the gallery image features are being updated.")]
public bool AllowUpdateImage { get; set; }
Comment thread
audreyttt marked this conversation as resolved.
}
}
1 change: 1 addition & 0 deletions src/Compute/Compute/Generated/Models/PSGalleryImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public string ResourceGroupName
public string Location { get; set; }
public IDictionary<string, string> Tags { get; set; }
public IList<GalleryImageFeature> Features { get; set; }
public bool? AllowUpdateImage { get; set; }
public string Architecture { get; set; }

}
Expand Down
55 changes: 53 additions & 2 deletions src/Compute/Compute/help/Update-AzGalleryImageDefinition.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Update-AzGalleryImageDefinition [-ResourceGroupName] <String> [-GalleryName] <St
[-MinimumMemory <Int32>] [-MinimumVCPU <Int32>] [-MaximumMemory <Int32>] [-MaximumVCPU <Int32>]
[-PrivacyStatementUri <String>] [-PurchasePlanName <String>] [-PurchasePlanProduct <String>]
[-PurchasePlanPublisher <String>] [-ReleaseNoteUri <String>] [-Tag <Hashtable>]
[-Feature <GalleryImageFeature[]>] [-AllowUpdateImage <Boolean>]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```
Expand All @@ -29,7 +30,8 @@ Update-AzGalleryImageDefinition [-ResourceId] <String> [-AsJob] [-Description <S
[-DisallowedDiskType <String[]>] [-EndOfLifeDate <DateTime>] [-Eula <String>] [-MinimumMemory <Int32>]
[-MinimumVCPU <Int32>] [-MaximumMemory <Int32>] [-MaximumVCPU <Int32>] [-PrivacyStatementUri <String>]
[-PurchasePlanName <String>] [-PurchasePlanProduct <String>] [-PurchasePlanPublisher <String>]
[-ReleaseNoteUri <String>] [-Tag <Hashtable>] [-DefaultProfile <IAzureContextContainer>]
[-ReleaseNoteUri <String>] [-Tag <Hashtable>] [-Feature <GalleryImageFeature[]>]
[-AllowUpdateImage <Boolean>] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

Expand All @@ -39,7 +41,8 @@ Update-AzGalleryImageDefinition [-InputObject] <PSGalleryImage> [-AsJob] [-Descr
[-DisallowedDiskType <String[]>] [-EndOfLifeDate <DateTime>] [-Eula <String>] [-MinimumMemory <Int32>]
[-MinimumVCPU <Int32>] [-MaximumMemory <Int32>] [-MaximumVCPU <Int32>] [-PrivacyStatementUri <String>]
[-PurchasePlanName <String>] [-PurchasePlanProduct <String>] [-PurchasePlanPublisher <String>]
[-ReleaseNoteUri <String>] [-Tag <Hashtable>] [-DefaultProfile <IAzureContextContainer>]
[-ReleaseNoteUri <String>] [-Tag <Hashtable>] [-Feature <GalleryImageFeature[]>]
[-AllowUpdateImage <Boolean>] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

Expand All @@ -66,6 +69,20 @@ Update-AzGalleryImageDefinition -ResourceGroupName $resourceGroupName -GalleryNa

Update a gallery image definition's recommended configuration settings

### Example 2: Update gallery image features with StartsAtVersion

```powershell
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$imageDefinitionName = "myImageDefinition"
$DiskControllerType = @{Name='DiskControllerTypes'; Value='SCSI'; StartsAtVersion='4.0.0'}
$SecurityType = @{Name='SecurityType'; Value='TrustedLaunch'; StartsAtVersion='4.0.0'}
Comment on lines +78 to +79
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example builds -Feature values as hashtables, but the parameter type is Microsoft.Azure.Management.Compute.Models.GalleryImageFeature[]. Unless a custom type converter exists, this example may not work as written. Update the example to construct actual GalleryImageFeature objects (e.g., via New-Object ... -Property @{...} or a strongly-typed cast) to match real usage (and align with the new scenario test).

Suggested change
$DiskControllerType = @{Name='DiskControllerTypes'; Value='SCSI'; StartsAtVersion='4.0.0'}
$SecurityType = @{Name='SecurityType'; Value='TrustedLaunch'; StartsAtVersion='4.0.0'}
$DiskControllerType = New-Object Microsoft.Azure.Management.Compute.Models.GalleryImageFeature -Property @{Name='DiskControllerTypes'; Value='SCSI'; StartsAtVersion='4.0.0'}
$SecurityType = New-Object Microsoft.Azure.Management.Compute.Models.GalleryImageFeature -Property @{Name='SecurityType'; Value='TrustedLaunch'; StartsAtVersion='4.0.0'}

Copilot uses AI. Check for mistakes.
$features = @($DiskControllerType, $SecurityType)
Update-AzGalleryImageDefinition -ResourceGroupName $rgName -GalleryName $galleryName -Name $imageDefinitionName -Feature $features -AllowUpdateImage $true
```

Update a gallery image definition's features, setting the minimum gallery image version that supports each feature via StartsAtVersion. The AllowUpdateImage parameter must be set to true when updating features.

## PARAMETERS

### -AsJob
Expand All @@ -83,6 +100,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -AllowUpdateImage
Must be set to `$true` when the gallery image features are being updated using the `-Feature` parameter.

```yaml
Type: System.Boolean
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -DefaultProfile
The credentials, account, tenant, and subscription used for communication with Azure.

Expand Down Expand Up @@ -158,6 +190,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -Feature
A list of gallery image features to update. Each feature can include a StartsAtVersion property to indicate the minimum gallery image version that supports it.

```yaml
Type: Microsoft.Azure.Management.Compute.Models.GalleryImageFeature[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -GalleryName
The name of the gallery.

Expand Down Expand Up @@ -431,6 +478,10 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable

### System.String[]

### Microsoft.Azure.Management.Compute.Models.GalleryImageFeature[]

### System.Boolean

## OUTPUTS

### Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImage
Expand Down
Loading