Skip to content

Commit 1425b11

Browse files
[Breaking Change] Default New-AzGalleryImageDefinition to HyperV Gen2 and Trusted Launch (#24869)
* development * finish feature dev * changelog and md file * add new test * update working in changelog * add one more scenario to test * assert line * collap function to one line code * add closing brace back to fix the error in code structure * update documentation * better wording * Update New-AzGalleryImageDefinition.md * Update New-AzGalleryImageDefinition.md --------- Co-authored-by: YanaXu <[email protected]>
1 parent b3336dc commit 1425b11

File tree

6 files changed

+1784
-3
lines changed

6 files changed

+1784
-3
lines changed

src/Compute/Compute.Test/ScenarioTests/GalleryTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,12 @@ public void TestGalleryVersionWithSourceImageVMId()
6464
{
6565
TestRunner.RunTestScript("Test-GalleryVersionWithSourceImageVMId");
6666
}
67+
68+
[Fact]
69+
[Trait(Category.AcceptanceType, Category.CheckIn)]
70+
public void TestGalleryImageDefinitionDefaults()
71+
{
72+
TestRunner.RunTestScript("Test-GalleryImageDefinitionDefaults");
73+
}
6774
}
6875
}

src/Compute/Compute.Test/ScenarioTests/GalleryTests.ps1

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,3 +893,100 @@ function Test-GalleryVersionWithSourceImageVMId
893893
Clean-ResourceGroup $rgname;
894894
}
895895
}
896+
897+
<#
898+
.SYNOPSIS
899+
Tests New-AzGalleryImageDefinition to default to HyperVGen V2 and TL
900+
#>
901+
function Test-GalleryImageDefinitionDefaults
902+
{
903+
# Setup
904+
$rgname = Get-ComputeTestResourceName;
905+
$loc = Get-ComputeVMLocation;
906+
907+
try
908+
{
909+
910+
$location = $loc;
911+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
912+
913+
# Gallery variables
914+
$resourceGroup = $rgname
915+
$galleryName = 'gl' + $rgname
916+
$definitionName = 'def' + $rgname
917+
$definitionName2 = $definitionName + '2'
918+
$skuDetails = @{
919+
Publisher = 'test'
920+
Offer = 'test'
921+
Sku = 'test'
922+
}
923+
$osType = 'Windows'
924+
$osState = 'Specialized'
925+
$storageAccountSku = 'Standard_LRS'
926+
927+
# Setup Image Gallery
928+
New-AzGallery -ResourceGroupName $rgname -Name $galleryName -location $location
929+
930+
# Setup Image Definition
931+
$paramNewAzImageDef = @{
932+
ResourceGroupName = $rgname
933+
GalleryName = $galleryName
934+
Name = $definitionName
935+
Publisher = $skuDetails.Publisher
936+
Offer = $skuDetails.Offer
937+
Sku = $skuDetails.Sku
938+
Location = $location
939+
OSState = $osState
940+
OsType = $osType
941+
ErrorAction = 'Stop'
942+
}
943+
944+
New-AzGalleryImageDefinition @paramNewAzImageDef;
945+
946+
$definition = Get-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName -Name $definitionName;
947+
948+
# verify HyperVGeneration and TL default
949+
Assert-AreEqual $definition.HyperVGeneration "V2";
950+
Assert-AreEqual $definition.features[0].Name "SecurityType";
951+
Assert-AreEqual $definition.features[0].Value "TrustedLaunchSupported";
952+
953+
954+
# Testing by passing TL default by explictly setting securityType
955+
956+
$skuDetails2 = @{
957+
Publisher = 'test0'
958+
Offer = 'test0'
959+
Sku = 'test0'
960+
}
961+
962+
$paramNewAzImageDef2 = @{
963+
ResourceGroupName = $rgname
964+
GalleryName = $galleryName
965+
Name = $definitionName2
966+
Publisher = $skuDetails2.Publisher
967+
Offer = $skuDetails2.Offer
968+
Sku = $skuDetails2.Sku
969+
Location = $location
970+
OSState = $osState
971+
OsType = $osType
972+
ErrorAction = 'Stop'
973+
Feature = @{Name="SecurityType"; Value="ConfidentialVM"}
974+
}
975+
976+
977+
New-AzGalleryImageDefinition @paramNewAzImageDef2
978+
$definition2 = Get-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName -Name $definitionName2;
979+
980+
# verify HyperVGeneration and TL default
981+
Assert-AreNotEqual $definition2.features[0].Value "TrustedLaunchSupported";
982+
Assert-AreEqual $definition2.features.count 1
983+
984+
985+
}
986+
finally
987+
{
988+
# Cleanup
989+
Clean-ResourceGroup $rgname;
990+
}
991+
}
992+

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.GalleryTests/TestGalleryImageDefinitionDefaults.json

Lines changed: 1638 additions & 0 deletions
Large diffs are not rendered by default.

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* [Breaking Change] Added ValidateNotNullOrEmpty for `-ResourceGroupName` and `-VMScaleSetName` parameters to `Get-AzVmss` cmdlet. [#20095]
2525
* Added `Etag` property to PSVirtualMachine and PSVirtualMachineScaleSet objects.
2626
* Added parameters `-IfMatch` and `-IfNoneMatch` to `Update-AzVM`, `Update-AzVmss`, `New-AzVm`, `New-AzVmss`, `New-AzVmConfig`, and `New-AzVmssConfig` cmdlets.
27+
* [Breaking Change] Cmdlet `New-AzGalleryImageDefinition` will default parameter `-HyperVGeneration` to `V2` if it is not set as `V1` explicitly, and also default parameter `-Feature` by adding `@{Name='SecurityType';Value='TrustedLaunchSupported'}` if the `SecurityType` feature is not set explicitly.
2728
* Resolved the bug with `New-AzVMConfig` for `-CommunityGalleryImageId` and `-SharedGalleryImageId` parameters.
2829
* [Breaking Change] Added ValidateNotNullOrEmpty for `-ResourceGroupName` and `-VMScaleSetName` parameters to `Get-AzVmss` cmdlet. [#20095]
2930
* [Breaking Change] Added new business logic to `New-AzVmss` and `New-AzVM` cmdlets. When the user explicitly sets the `SecurityType` to `Standard`, the Image alias defaults to `Win2022AzureEdition` to make future migrations to Trusted Launch easier.

src/Compute/Compute/Generated/GalleryImage/GalleryImageCreateOrUpdateMethod.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public override void ExecuteCmdlet()
6868
{
6969
galleryImage.HyperVGeneration = this.HyperVGeneration;
7070
}
71+
else //default HyperVGenration V2 if not specified
72+
{
73+
galleryImage.HyperVGeneration = "V2";
74+
}
7175

7276
if (this.IsParameterBound(c => c.PrivacyStatementUri))
7377
{
@@ -184,7 +188,20 @@ public override void ExecuteCmdlet()
184188

185189
if (this.IsParameterBound(c => c.Feature))
186190
{
187-
galleryImage.Features = this.Feature;
191+
galleryImage.Features = new List<GalleryImageFeature>();
192+
for (int i = 0; i < this.Feature.Length; i++)
193+
{
194+
galleryImage.Features.Add(this.Feature[i]);
195+
}
196+
}
197+
198+
if ((!this.IsParameterBound(c => c.Feature) || galleryImage.Features?.All(f => f.Name.ToLower() != "securitytype") == true) && galleryImage.HyperVGeneration == "V2")
199+
{
200+
if (galleryImage.Features == null)
201+
{
202+
galleryImage.Features = new List<GalleryImageFeature>();
203+
}
204+
galleryImage.Features.Add(new GalleryImageFeature("SecurityType", "TrustedLaunchSupported"));
188205
}
189206

190207
var result = GalleryImagesClient.CreateOrUpdate(resourceGroupName, galleryName, galleryImageName, galleryImage);

src/Compute/Compute/help/New-AzGalleryImageDefinition.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ New-AzGalleryImageDefinition [-ResourceGroupName] <String> [-GalleryName] <Strin
2727

2828
## DESCRIPTION
2929

30-
Create a gallery image definition.
30+
Create a gallery image definition.
31+
The gallery image definition will default to 'HyperVGeneration: V2' and 'SecurityType: TrustedLaunchSupported' if `-HyperVGeneration` and `-Feature @{Name: SecurityType}` is not set explicitly. Set SecurityType to 'None' to opt out of this defaulting (See Example 10).
3132

3233
## EXAMPLES
3334

@@ -45,7 +46,7 @@ $description = "My gallery"
4546
New-AzGalleryImageDefinition -ResourceGroupName $rgName -GalleryName $galleryName -Name $galleryImageDefinitionName -Location $location -Publisher $publisherName -Offer $offerName -Sku $skuName -OsState "Specialized" -OsType "Linux" -Description $description
4647
```
4748

48-
Creates a gallery image definition to contain image versions for specialized linux images.
49+
Creates a gallery image definition to contain image versions for specialized linux images. This will default the Gallery Image to HyperVGeneration V2 and Trusted Launch as `-HyperVGeneration` and `-Feature SecurityType` is not set explicitly.
4950

5051
### Example 2: Create an image definition for generalized linux images
5152

@@ -186,6 +187,25 @@ New-AzGalleryImageDefinition -ResourceGroupName $rgName -GalleryName $galleryNam
186187

187188
Creates a gallery image definition for linux generalized images and specify either the string or path to an EULA agreement, privacy statement, and release notes tied to all image versions in the image definition.
188189

190+
### Example 10: Create a gallery image definition with Standard SecurityType feature
191+
192+
```powershell
193+
$rgName = "myResourceGroup"
194+
$galleryName = "myGallery"
195+
$galleryImageDefinitionName = "myImage"
196+
$location = "eastus"
197+
$publisherName = "GreatPublisher"
198+
$offerName = "GreatOffer"
199+
$skuName = "GreatSku"
200+
201+
$Feature1 = @{Name='SecurityType';Value='None'}
202+
$Features = @($Feature1)
203+
204+
New-AzGalleryImageDefinition -ResourceGroupName $rgName -GalleryName $galleryName -Name $galleryImageDefinitionName -Location $location -Publisher $publisherName -Offer $offerName -Sku $skuName -OsState "Generalized" -OsType "Linux" -Feature $Features
205+
```
206+
207+
Create a gallery image definition with standard security type feature by providing 'None' as the value of the SecurityType feature.
208+
189209
## PARAMETERS
190210

191211
### -Architecture
@@ -302,6 +322,7 @@ Accept wildcard characters: False
302322
### -Feature
303323
304324
A list of gallery image features.
325+
For SecurityType, acceptable inputs are: None, TrustedlaunchSupported, Trustedlaunch, ConfidentialVM, ConfidentialVMSupported, TrustedandConfidentialVMSupported
305326
306327
```yaml
307328
Type: Microsoft.Azure.Management.Compute.Models.GalleryImageFeature[]

0 commit comments

Comments
 (0)