Skip to content

Commit 01fba5d

Browse files
grizzlytheodoreTheodore Chang
andauthored
New-AzGalleryImageVersion update property mapping (Azure#19779)
* update encryption property * update md * changelog * Update ChangeLog.md Co-authored-by: Theodore Chang <[email protected]>
1 parent 7f7a655 commit 01fba5d

File tree

3 files changed

+28
-37
lines changed

3 files changed

+28
-37
lines changed

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
-->
2222
## Upcoming Release
23+
* For `New-AzGalleryImageVersion`, update property mapping for `Encryption`.
2324

2425
## Version 4.32.0
2526
* Added the `TimeCreated` property to the Virtual Machine and Virtual Machine Scale Set models.

src/Compute/Compute/Generated/GalleryImageVersion/GalleryImageVersionCreateOrUpdateMethod.cs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,21 @@ public override void ExecuteCmdlet()
128128
};
129129
if (t["Encryption"] != null)
130130
{
131-
var osDiskEncryptionSetId = (string)((Hashtable)((Hashtable)t["Encryption"])["osDiskImage"])["DiskEncryptionSetId"];
132-
var osDiskImageEncryption = new OSDiskImageEncryption(osDiskEncryptionSetId);
131+
OSDiskImageEncryption osDiskImageEncryption = new OSDiskImageEncryption();
132+
if (((Hashtable)((Hashtable)t["Encryption"])["osDiskImage"]) != null)
133+
{
134+
var osDiskEncryptionSetId = (string)((Hashtable)((Hashtable)t["Encryption"])["osDiskImage"])["DiskEncryptionSetId"];
135+
osDiskImageEncryption.DiskEncryptionSetId = osDiskEncryptionSetId;
136+
137+
var cVMEncryptionType = (string)((Hashtable)((Hashtable)t["Encryption"])["osDiskImage"])["CVMEncryptionType"];
138+
var cVMDiskEncryptionSetID = (string)((Hashtable)((Hashtable)t["Encryption"])["osDiskImage"])["CVMDiskEncryptionSetID"];
139+
if (cVMEncryptionType != null || cVMDiskEncryptionSetID != null)
140+
{
141+
OSDiskImageSecurityProfile osDiskImageSecurityProfile = new OSDiskImageSecurityProfile(cVMEncryptionType, cVMDiskEncryptionSetID);
142+
osDiskImageEncryption.SecurityProfile = osDiskImageSecurityProfile;
143+
}
144+
145+
}
133146

134147
List<DataDiskImageEncryption> dataDiskImageEncryption = null;
135148
var dataDiskImage = (object[])((Hashtable)t["Encryption"])["dataDiskImages"];
@@ -147,34 +160,6 @@ public override void ExecuteCmdlet()
147160
target.Encryption = new EncryptionImages(osDiskImageEncryption, dataDiskImageEncryption);
148161
}
149162

150-
if (t["CVMEncryptionType"] != null)
151-
{
152-
if (target.Encryption == null)
153-
{
154-
target.Encryption = new EncryptionImages();
155-
}
156-
target.Encryption.OsDiskImage = new OSDiskImageEncryption();
157-
target.Encryption.OsDiskImage.SecurityProfile = new OSDiskImageSecurityProfile();
158-
target.Encryption.OsDiskImage.SecurityProfile.ConfidentialVMEncryptionType = (string)t["CVMEncryptionType"];
159-
}
160-
161-
if (t["CVMDiskEncryptionSetID"] != null)
162-
{
163-
if (target.Encryption == null)
164-
{
165-
target.Encryption = new EncryptionImages();
166-
}
167-
if (target.Encryption.OsDiskImage == null)
168-
{
169-
target.Encryption.OsDiskImage = new OSDiskImageEncryption();
170-
}
171-
if (target.Encryption.OsDiskImage.SecurityProfile == null)
172-
{
173-
target.Encryption.OsDiskImage.SecurityProfile = new OSDiskImageSecurityProfile();
174-
}
175-
target.Encryption.OsDiskImage.SecurityProfile.SecureVMDiskEncryptionSetId = (string)t["CVMDiskEncryptionSetID"];
176-
}
177-
178163
galleryImageVersion.PublishingProfile.TargetRegions.Add(target);
179164
}
180165
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,21 @@ $galleryName = "myGallery"
154154
$galleryImageDefinitionName = "myImage"
155155
$galleryImageVersionName = "1.0.0"
156156
$location = "eastus"
157+
157158
$sourceImageId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myVMRG/providers/Microsoft.Compute/virtualMachines/myVM"
158159
$diskEncryptionSetId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myVMRG/providers/Microsoft.Compute/diskEncryptionSets/cvmDiskEncryptionSet"
159-
$replicaCount = 1
160-
$storageAccountType = "Standard_ZRS"
161-
$region_eastus = @{Name = 'East US';ReplicaCount = 3;StorageAccountType = 'Standard_LRS'; CVMEncryptionType="EncryptedWithCmk"; CVMDiskEncryptionSetID=$diskEncryptionSetId}
162-
$region_westus = @{Name = 'West US'}
160+
161+
$cvmOsDiskEncryption = @{CVMEncryptionType=EncryptedWithCmk; CVMDiskEncryptionSetID=$diskEncryptionSetId}
162+
163+
$cvmDataDiskEncryption_lun0 = @{DiskEncryptionSetId = $diskEncryptionSetId ; Lun = 0}
164+
$cvmDataDiskEncryption = @($cvmDataDiskEncryption_lun0)
165+
166+
$cvmEncryption = @{OSDiskImage = $cvmOsDiskEncryption; DataDiskImages = $cvmDataDiskEncryption}
167+
$region_eastus = @{Name = 'East US';ReplicaCount = 3;StorageAccountType = 'Standard_LRS'; Encryption = $cvmEncryption}
163168
$region_ukwest = @{Name = 'UK West';ReplicaCount = 2}
164-
$region_southcentralus = @{Name = 'South Central US';StorageAccountType = 'Standard_LRS'}
165-
$targetRegions = @($region_eastus, $region_westus, $region_ukwest, $region_southcentralus)
166-
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -SourceImageId $sourceImageId -ReplicaCount 1 -StorageAccountType $storageAccountType -TargetRegion $targetRegions
169+
$targetRegions = @($region_eastus, $region_ukwest)
170+
171+
New-AzGalleryImageVersion -ResourceGroupName $rgName -GalleryName $galleryName -GalleryImageDefinitionName $galleryImageDefinitionName -Name $galleryImageVersionName -Location $location -SourceImageId $sourceImageId -ReplicaCount 1 -StorageAccountType "Standard_ZRS" -TargetRegion $targetRegions
167172
```
168173

169174
Create an image version in four regions. In this example, the global replica count is 1 and the global storage account type is Standard_ZRS. East US will have 3 replicas, each stored on Standard_LRS account storage. West US will inherit from global settings and have 1 replica stored on Standard_ZRS. UK West will have a replica count of 2 stored on Standard_ZRS. South Central US will have one replica stored on Standard_LRS.

0 commit comments

Comments
 (0)