Skip to content

Commit 2b581cf

Browse files
committed
Update Set-AzureRmOsDisk cmdlet for disk encryption
1 parent 69044ea commit 2b581cf

File tree

8 files changed

+111
-11
lines changed

8 files changed

+111
-11
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/Commands.Compute.Test.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@
6666
<Reference Include="Microsoft.Azure.Management.Authorization">
6767
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.1.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
6868
</Reference>
69-
<Reference Include="Microsoft.Azure.Management.Compute, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
70-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.9.0.0\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>
71-
<Private>True</Private>
69+
<Reference Include="Microsoft.Azure.Management.Compute.Internal">
70+
<HintPath>..\..\..\packages\dedll\Microsoft.Azure.Management.Compute.Internal.dll</HintPath>
7271
</Reference>
7372
<Reference Include="Microsoft.Azure.Management.Network, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7473
<SpecificVersion>False</SpecificVersion>

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,22 @@ function Test-VirtualMachineProfileWithoutAUC
244244
$dataDiskVhdUri2 = "https://$stoname.blob.core.windows.net/test/data2.vhd";
245245
$dataDiskVhdUri3 = "https://$stoname.blob.core.windows.net/test/data3.vhd";
246246

247-
$p = Set-AzureRmVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption Empty;
247+
$dekUri = "https://testvault123.vault.azure.net/secrets/Test1/514ceb769c984379a7e0230bddaaaaaa";
248+
$dekId = "/subscriptions/" + $subid + "/resourceGroups/RgTest1/providers/Microsoft.KeyVault/vaults/TestVault123";
249+
$kekUri = "http://keyVaultName.vault.azure.net/secrets/secretName/secretVersion";
250+
$kekId = "/subscriptions/" + $subid + "/resourceGroups/RgTest1/providers/Microsoft.KeyVault/vaults/TestVault123";
251+
252+
$p = Set-AzureRmVMOSDisk -VM $p -Windows -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption Empty -DiskEncryptionKeyUrl $dekUri -DiskEncryptionKeyVaultId $dekId -KeyEncryptionKeyUrl $kekUri -KeyEncryptionKeyVaultId $kekId;
248253

249254
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 0 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
250255
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri $dataDiskVhdUri2 -CreateOption Empty;
251256
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk3' -Caching 'ReadOnly' -DiskSizeInGB 12 -Lun 2 -VhdUri $dataDiskVhdUri3 -CreateOption Empty;
252257
$p = Remove-AzureRmVMDataDisk -VM $p -Name 'testDataDisk3';
253258

259+
Assert-AreEqual $p.StorageProfile.OSDisk.EncryptionSettings.DiskEncryptionKey.SourceVault.ReferenceUri $dekId
260+
Assert-AreEqual $p.StorageProfile.OSDisk.EncryptionSettings.DiskEncryptionKey.SecretUrl $dekUri
261+
Assert-AreEqual $p.StorageProfile.OSDisk.EncryptionSettings.KeyEncryptionKey.SourceVault.ReferenceUri $kekId
262+
Assert-AreEqual $p.StorageProfile.OSDisk.EncryptionSettings.KeyEncryptionKey.KeyUrl $kekUri
254263
Assert-AreEqual $p.StorageProfile.OSDisk.Caching $osDiskCaching;
255264
Assert-AreEqual $p.StorageProfile.OSDisk.Name $osDiskName;
256265
Assert-AreEqual $p.StorageProfile.OSDisk.VirtualHardDisk.Uri $osDiskVhdUri;

src/ResourceManager/Compute/Commands.Compute.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Graph.RBAC" version="1.7.0-preview" targetFramework="net45" />
99
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
10-
<package id="Microsoft.Azure.Management.Compute" version="9.0.0" targetFramework="net45" />
10+
<!-- <package id="Microsoft.Azure.Management.Compute" version="9.0.0" targetFramework="net45" /> -->
1111
<package id="Microsoft.Azure.Management.Network" version="2.0.13-preview" targetFramework="net45" />
1212
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
1313
<package id="Microsoft.Azure.Management.Storage" version="2.4.0-preview" targetFramework="net45" />

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@
8080
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.1.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
8181
<Private>True</Private>
8282
</Reference>
83-
<Reference Include="Microsoft.Azure.Management.Compute, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
84-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.9.0.0\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>
85-
<Private>True</Private>
83+
<Reference Include="Microsoft.Azure.Management.Compute.Internal">
84+
<HintPath>..\..\..\packages\dedll\Microsoft.Azure.Management.Compute.Internal.dll</HintPath>
8685
</Reference>
8786
<Reference Include="Microsoft.Azure.Management.Network, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
8887
<SpecificVersion>False</SpecificVersion>

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMOSDiskCommand.cs

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ namespace Microsoft.Azure.Commands.Compute
2525
[Cmdlet(
2626
VerbsCommon.Set,
2727
ProfileNouns.OSDisk,
28-
DefaultParameterSetName = WindowsParamSet),
28+
DefaultParameterSetName = DefaultParamSet),
2929
OutputType(
3030
typeof(PSVirtualMachine))]
3131
public class SetAzureVMOSDiskCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
3232
{
33+
protected const string DefaultParamSet = "DefaultParamSet";
3334
protected const string WindowsParamSet = "WindowsParamSet";
3435
protected const string LinuxParamSet = "LinuxParamSet";
36+
protected const string WindowsDiskEncryptionParameterSet = "WindowsDiskEncryptionParameterSet";
37+
protected const string LinuxDiskEncryptionParameterSet = "LinuxDiskEncryptionParameterSet";
3538

3639
[Alias("VMProfile")]
3740
[Parameter(
@@ -90,15 +93,81 @@ public class SetAzureVMOSDiskCommand : Microsoft.Azure.Commands.ResourceManager.
9093
Position = 6,
9194
ValueFromPipelineByPropertyName = true,
9295
HelpMessage = HelpMessages.VMOSDiskWindowsOSType)]
96+
[Parameter(
97+
ParameterSetName = WindowsDiskEncryptionParameterSet,
98+
Position = 6,
99+
ValueFromPipelineByPropertyName = true,
100+
HelpMessage = HelpMessages.VMOSDiskWindowsOSType)]
93101
public SwitchParameter Windows { get; set; }
94102

95103
[Parameter(
96104
ParameterSetName = LinuxParamSet,
97105
Position = 6,
98106
ValueFromPipelineByPropertyName = true,
99107
HelpMessage = HelpMessages.VMOSDiskLinuxOSType)]
108+
[Parameter(
109+
ParameterSetName = LinuxDiskEncryptionParameterSet,
110+
Position = 6,
111+
ValueFromPipelineByPropertyName = true,
112+
HelpMessage = HelpMessages.VMOSDiskLinuxOSType)]
100113
public SwitchParameter Linux { get; set; }
101114

115+
[Parameter(
116+
ParameterSetName = WindowsDiskEncryptionParameterSet,
117+
Mandatory = true,
118+
Position = 7,
119+
ValueFromPipelineByPropertyName = true,
120+
HelpMessage = HelpMessages.VMOSDiskLinuxOSType)]
121+
[Parameter(
122+
ParameterSetName = LinuxDiskEncryptionParameterSet,
123+
Mandatory = true,
124+
Position = 7,
125+
ValueFromPipelineByPropertyName = true,
126+
HelpMessage = HelpMessages.VMOSDiskLinuxOSType)]
127+
public Uri DiskEncryptionKeyUrl { get; set; }
128+
129+
[Parameter(
130+
ParameterSetName = WindowsDiskEncryptionParameterSet,
131+
Mandatory = true,
132+
Position = 8,
133+
ValueFromPipelineByPropertyName = true,
134+
HelpMessage = HelpMessages.VMOSDiskLinuxOSType)]
135+
[Parameter(
136+
ParameterSetName = LinuxDiskEncryptionParameterSet,
137+
Mandatory = true,
138+
Position = 8,
139+
ValueFromPipelineByPropertyName = true,
140+
HelpMessage = HelpMessages.VMOSDiskLinuxOSType)]
141+
public string DiskEncryptionKeyVaultId { get; set; }
142+
143+
[Parameter(
144+
ParameterSetName = WindowsDiskEncryptionParameterSet,
145+
Mandatory = false,
146+
Position = 9,
147+
ValueFromPipelineByPropertyName = true,
148+
HelpMessage = HelpMessages.VMOSDiskLinuxOSType)]
149+
[Parameter(
150+
ParameterSetName = LinuxDiskEncryptionParameterSet,
151+
Mandatory = false,
152+
Position = 9,
153+
ValueFromPipelineByPropertyName = true,
154+
HelpMessage = HelpMessages.VMOSDiskLinuxOSType)]
155+
public Uri KeyEncryptionKeyUrl { get; set; }
156+
157+
[Parameter(
158+
ParameterSetName = WindowsDiskEncryptionParameterSet,
159+
Mandatory = false,
160+
Position = 10,
161+
ValueFromPipelineByPropertyName = true,
162+
HelpMessage = HelpMessages.VMOSDiskLinuxOSType)]
163+
[Parameter(
164+
ParameterSetName = LinuxDiskEncryptionParameterSet,
165+
Mandatory = false,
166+
Position = 10,
167+
ValueFromPipelineByPropertyName = true,
168+
HelpMessage = HelpMessages.VMOSDiskLinuxOSType)]
169+
public string KeyEncryptionKeyVaultId { get; set; }
170+
102171
protected override void ProcessRecord()
103172
{
104173
if (this.VM.StorageProfile == null)
@@ -119,7 +188,31 @@ protected override void ProcessRecord()
119188
{
120189
Uri = this.SourceImageUri
121190
},
122-
CreateOption = this.CreateOption
191+
CreateOption = this.CreateOption,
192+
EncryptionSettings =
193+
(this.ParameterSetName.Equals(WindowsDiskEncryptionParameterSet) || this.ParameterSetName.Equals(WindowsDiskEncryptionParameterSet))
194+
? new DiskEncryptionSettings
195+
{
196+
DiskEncryptionKey = new KeyVaultSecretReference
197+
{
198+
SourceVault = new SourceVaultReference
199+
{
200+
ReferenceUri = this.DiskEncryptionKeyVaultId
201+
},
202+
SecretUrl = this.DiskEncryptionKeyUrl
203+
},
204+
KeyEncryptionKey = (this.KeyEncryptionKeyVaultId == null || this.KeyEncryptionKeyUrl == null)
205+
? null
206+
: new KeyVaultKeyReference
207+
{
208+
KeyUrl = this.KeyEncryptionKeyUrl,
209+
SourceVault = new SourceVaultReference
210+
{
211+
ReferenceUri = this.KeyEncryptionKeyVaultId
212+
},
213+
}
214+
}
215+
: null
123216
};
124217

125218
WriteObject(this.VM);

src/ResourceManager/Compute/Commands.Compute/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<package id="Microsoft.Azure.Graph.RBAC" version="1.7.0-preview" targetFramework="net45" />
1010
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
1111
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
12-
<package id="Microsoft.Azure.Management.Compute" version="9.0.0" targetFramework="net45" />
12+
<!-- <package id="Microsoft.Azure.Management.Compute" version="9.0.0" targetFramework="net45" /> -->
1313
<package id="Microsoft.Azure.Management.Network" version="2.0.13-preview" targetFramework="net45" />
1414
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
1515
<package id="Microsoft.Azure.Management.Storage" version="2.4.0-preview" targetFramework="net45" />
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)