-
Notifications
You must be signed in to change notification settings - Fork 3
Update Set-AzureRmOsDisk cmdlet for Disk Encryption #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2b581cf
c49c1d8
ab23f61
bc093a1
aa314db
e503572
04d9c7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,13 +25,16 @@ namespace Microsoft.Azure.Commands.Compute | |
[Cmdlet( | ||
VerbsCommon.Set, | ||
ProfileNouns.OSDisk, | ||
DefaultParameterSetName = WindowsParamSet), | ||
DefaultParameterSetName = DefaultParamSet), | ||
OutputType( | ||
typeof(PSVirtualMachine))] | ||
public class SetAzureVMOSDiskCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet | ||
{ | ||
protected const string DefaultParamSet = "DefaultParamSet"; | ||
protected const string WindowsParamSet = "WindowsParamSet"; | ||
protected const string LinuxParamSet = "LinuxParamSet"; | ||
protected const string WindowsAndDiskEncryptionParameterSet = "WindowsDiskEncryptionParameterSet"; | ||
protected const string LinuxAndDiskEncryptionParameterSet = "LinuxDiskEncryptionParameterSet"; | ||
|
||
[Alias("VMProfile")] | ||
[Parameter( | ||
|
@@ -90,22 +93,96 @@ public class SetAzureVMOSDiskCommand : Microsoft.Azure.Commands.ResourceManager. | |
Position = 6, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = HelpMessages.VMOSDiskWindowsOSType)] | ||
[Parameter( | ||
ParameterSetName = WindowsAndDiskEncryptionParameterSet, | ||
Position = 6, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = HelpMessages.VMOSDiskWindowsOSType)] | ||
public SwitchParameter Windows { get; set; } | ||
|
||
[Parameter( | ||
ParameterSetName = LinuxParamSet, | ||
Position = 6, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = HelpMessages.VMOSDiskLinuxOSType)] | ||
[Parameter( | ||
ParameterSetName = LinuxAndDiskEncryptionParameterSet, | ||
Position = 6, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = HelpMessages.VMOSDiskLinuxOSType)] | ||
public SwitchParameter Linux { get; set; } | ||
|
||
[Parameter( | ||
ParameterSetName = WindowsAndDiskEncryptionParameterSet, | ||
Mandatory = true, | ||
Position = 7, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = HelpMessages.VMOSDiskDiskEncryptionKeyUrl)] | ||
[Parameter( | ||
ParameterSetName = LinuxAndDiskEncryptionParameterSet, | ||
Mandatory = true, | ||
Position = 7, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = HelpMessages.VMOSDiskDiskEncryptionKeyUrl)] | ||
public string DiskEncryptionKeyUrl { get; set; } | ||
|
||
[Parameter( | ||
ParameterSetName = WindowsAndDiskEncryptionParameterSet, | ||
Mandatory = true, | ||
Position = 8, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = HelpMessages.VMOSDiskDiskEncryptionKeyVaultId)] | ||
[Parameter( | ||
ParameterSetName = LinuxAndDiskEncryptionParameterSet, | ||
Mandatory = true, | ||
Position = 8, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = HelpMessages.VMOSDiskDiskEncryptionKeyVaultId)] | ||
public string DiskEncryptionKeyVaultId { get; set; } | ||
|
||
[Parameter( | ||
ParameterSetName = WindowsAndDiskEncryptionParameterSet, | ||
Mandatory = false, | ||
Position = 9, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = HelpMessages.VMOSDiskKeyEncryptionKeyUrl)] | ||
[Parameter( | ||
ParameterSetName = LinuxAndDiskEncryptionParameterSet, | ||
Mandatory = false, | ||
Position = 9, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = HelpMessages.VMOSDiskKeyEncryptionKeyUrl)] | ||
public string KeyEncryptionKeyUrl { get; set; } | ||
|
||
[Parameter( | ||
ParameterSetName = WindowsAndDiskEncryptionParameterSet, | ||
Mandatory = false, | ||
Position = 10, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = HelpMessages.VMOSDiskKeyEncryptionKeyVaultId)] | ||
[Parameter( | ||
ParameterSetName = LinuxAndDiskEncryptionParameterSet, | ||
Mandatory = false, | ||
Position = 10, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = HelpMessages.VMOSDiskKeyEncryptionKeyVaultId)] | ||
public string KeyEncryptionKeyVaultId { get; set; } | ||
|
||
protected override void ProcessRecord() | ||
{ | ||
if (this.VM.StorageProfile == null) | ||
{ | ||
this.VM.StorageProfile = new StorageProfile(); | ||
} | ||
|
||
if ((string.IsNullOrEmpty(this.KeyEncryptionKeyVaultId) && !string.IsNullOrEmpty(this.KeyEncryptionKeyUrl)) | ||
|| (!string.IsNullOrEmpty(this.KeyEncryptionKeyVaultId) && string.IsNullOrEmpty(this.KeyEncryptionKeyUrl))) | ||
{ | ||
WriteError(new ErrorRecord( | ||
new Exception(Properties.Resources.VMOSDiskDiskEncryptionBothKekVaultIdAndKekUrlRequired), | ||
string.Empty, ErrorCategory.InvalidArgument, null)); | ||
} | ||
|
||
this.VM.StorageProfile.OSDisk = new OSDisk | ||
{ | ||
Caching = this.Caching, | ||
|
@@ -119,7 +196,31 @@ protected override void ProcessRecord() | |
{ | ||
Uri = this.SourceImageUri | ||
}, | ||
CreateOption = this.CreateOption | ||
CreateOption = this.CreateOption, | ||
EncryptionSettings = | ||
(this.ParameterSetName.Equals(WindowsAndDiskEncryptionParameterSet) || this.ParameterSetName.Equals(LinuxAndDiskEncryptionParameterSet)) | ||
? new DiskEncryptionSettings | ||
{ | ||
DiskEncryptionKey = new KeyVaultSecretReference | ||
{ | ||
SourceVault = new SourceVaultReference | ||
{ | ||
ReferenceUri = this.DiskEncryptionKeyVaultId | ||
}, | ||
SecretUrl = this.DiskEncryptionKeyUrl | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Referring to the client field, the PS parameter probably should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These parameter names are decided after discussion. If we follow the client field, it should be DiskEncryptionKeySecretUrl, but it feels redundunt, so removed 'Secret'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. Thanks. |
||
}, | ||
KeyEncryptionKey = (this.KeyEncryptionKeyVaultId == null || this.KeyEncryptionKeyUrl == null) | ||
? null | ||
: new KeyVaultKeyReference | ||
{ | ||
KeyUrl = this.KeyEncryptionKeyUrl, | ||
SourceVault = new SourceVaultReference | ||
{ | ||
ReferenceUri = this.KeyEncryptionKeyVaultId | ||
}, | ||
} | ||
} | ||
: null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about linux? |
||
}; | ||
|
||
WriteObject(this.VM); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could probably mandate this in a separate parameter set, i.e.
WindowsDiskAndKeyEncryptionParameterSet
.