Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f5b64a1
Adding SecurityProfile and EncryptionAtHost property
haagha Jul 17, 2020
e9b862c
Removing deprecated package
haagha Jul 17, 2020
692dbf7
Adding back windowsazure.storage library
haagha Jul 17, 2020
6563638
reverting to version 9.3
haagha Jul 17, 2020
9c159ef
commenting out check for now
haagha Jul 17, 2020
25ef7d7
commenting out test case
haagha Jul 20, 2020
8283d41
Fixing powershell script
haagha Jul 20, 2020
2803b8f
Changing Compute Version for upstream
haagha Jul 20, 2020
07b6088
fixing test
haagha Jul 21, 2020
44697f0
Commenting out test
haagha Jul 22, 2020
221f244
Adding change log and helpdocs
haagha Jul 23, 2020
d6ad36b
New-Azvmss dev edits
Sandido Jul 24, 2020
80d7199
Testing and other changes
haagha Jul 24, 2020
44e349c
Merge branch 'encryptionAtHostParam' into haider/encryptionathost
haagha Jul 24, 2020
8d74d64
update-azvmss dev edits
Sandido Jul 24, 2020
5b68675
New-AzvmssConfig dev edits
Sandido Jul 24, 2020
cb30654
EncryptionAtHost and SecurityProfile changes for New-AzVM, New-AzVMCo…
haagha Jul 24, 2020
1fbab6b
included test for New-Azvmss and test file. Test for NEw-AzvmssConfig…
Sandido Jul 27, 2020
220c1e8
Merge branch 'encryptionAtHostParam' of https://github.com/Azure/azur…
Sandido Jul 27, 2020
04a80bf
Update NewAzureRmVmssConfigCommand.cs
haagha Jul 28, 2020
55e0b63
Changing Update-AzVM EncryptionAtHost param to Bool from Switch
haagha Jul 28, 2020
6c6044e
Merge branch 'haider/encryptionathost' of https://github.com/haagha/a…
haagha Jul 28, 2020
8448db3
Adding Update-AzVM changes
haagha Jul 28, 2020
f249347
Update ChangeLog.md
Jul 28, 2020
c0cd321
Merging master into encryptionAtHostParam
haagha Jul 29, 2020
db62207
Merge branch 'encryptionAtHostParam' of https://github.com/Azure/azur…
haagha Jul 29, 2020
d4f70b9
-development for update-azvmss new-azvmss new-azvmssconfig
Jul 29, 2020
b7b02f1
Merge branch 'encryptionAtHostParam' of https://github.com/Azure/azur…
Jul 29, 2020
79f58bb
Correct the format of a generated example
isra-fel Jul 30, 2020
262802b
Update Update-AzVM.md
haagha Jul 30, 2020
9ea3e0e
Update NewAzureVMCommand.cs
haagha Jul 30, 2020
cbfe2df
Update ChangeLog.md
haagha Jul 30, 2020
ba0e503
update wildcard support value
Jul 30, 2020
da50965
Merge branch 'encryptionAtHostParam' of https://github.com/Azure/azur…
Jul 30, 2020
ac6acb9
new line edits
Jul 30, 2020
673119f
Fixing a small bug and test case
haagha Aug 3, 2020
92fa3de
Merge branch 'master' into encryptionAtHostParam
haagha Aug 3, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,12 @@ public void TestVirtualMachineScaleSetImageVersion()
{
TestRunner.RunTestScript("Test-VirtualMachineScaleSetImageVersion");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualMachineScaleSetNewEncryptionAtHost()
{
TestRunner.RunTestScript("Test-VirtualMachineScaleSetEncryptionAtHost");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2467,3 +2467,72 @@ function Test-VirtualMachineScaleSetImageVersion
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
testing encryptionAtHost cmdlet for
new-azvmss - create vmss using simple parameter set and hostencryption tag.
update-azvmss test boolean parameter
new-azvmssconfig
#>
function Test-VirtualMachineScaleSetEncryptionAtHost
{
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
$loc = Get-Location "Microsoft.Compute" "virtualMachines";
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# SRP
$stoname = 'sto' + $rgname;
$stotype = 'Standard_GRS';
New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
$stoaccount = Get-AzStorageAccount -ResourceGroupName $rgname -Name $stoname;

# NRP
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
$subnetId = $vnet.Subnets[0].Id;

# New VMSS Parameters
$vmssName = 'vmsswithconfig';
$adminUsername = 'Foo12';
$adminPassword = $PLACEHOLDER;

$securePassword = ConvertTo-SecureString $adminPassword -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $securePassword);


$imgRef = Get-DefaultCRPImage -loc $loc;
$ipCfg = New-AzVmssIPConfig -Name 'test' -SubnetId $subnetId;

$vmss = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName 'Standard_E4-2ds_v4' -UpgradePolicyMode 'Manual' -EncryptionAtHost `
| Add-AzVmssNetworkInterfaceConfiguration -Name 'test' -Primary $true -IPConfiguration $ipCfg `
| Set-AzVmssOSProfile -ComputerNamePrefix 'test' -AdminUsername $adminUsername -AdminPassword $adminPassword `
| Set-AzVmssStorageProfile -OsDiskCreateOption 'FromImage' -OsDiskCaching 'None' `
-ImageReferenceOffer $imgRef.Offer -ImageReferenceSku $imgRef.Skus -ImageReferenceVersion 'latest' `
-ImageReferencePublisher $imgRef.PublisherName ;

#creating vmss using new-azvmss default parameter set which uses New-VmssConfig with -EncryptionAtHost parameter
$vmssResult1 = New-AzVmss -ResourceGroupName $rgname -Name $vmssName -VirtualMachineScaleSet $vmss
#creating vmss using New-azvmss simple parameter set
$vmssResult2 = New-AzVmss -ResourceGroupName $rgname -VMScaleSetName "newvmss" -Credential $cred -EncryptionAtHost -DomainNameLabel "domainlabel"

Assert-AreEqual $vmssResult1.VirtualMachineProfile.SecurityProfile.EncryptionAtHost True;
Assert-AreEqual $vmssResult2.VirtualMachineProfile.SecurityProfile.EncryptionAtHost True;

#using Update-azvmss to turn off encryptionAtHost
$updatedVM = Update-azvmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -VirtualMachineScaleSet $vmssResult1 -EncryptionAtHost $false

Assert-False { $updatedVM.VirtualMachineProfile.SecurityProfile.EncryptionAtHost };
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}
14 changes: 14 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,20 @@ public void TestLowPriorityVirtualMachine()
TestRunner.RunTestScript("Test-LowPriorityVirtualMachine");
}

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

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

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSetAzVMOperatingSystem()
Expand Down
156 changes: 156 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3854,6 +3854,162 @@ function Test-LowPriorityVirtualMachine
}
}

<#
.SYNOPSIS
Test EncryptionAtHost Virtual Machine
#>
function Test-EncryptionAtHostVM
{
# Setup
$rgname = Get-ComputeTestResourceName

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

# VM Profile & Hardware

$vmsize = 'Standard_DS2_v2';
$vmname = 'vm' + $rgname;
[string]$domainNameLabel = "$vmname-$vmname".tolower();

$user = "Foo2";
$password = $PLACEHOLDER;
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
$computerName = 'test';

New-AzVM -ResourceGroupName $rgname -Name $vmname -Credential $cred -DomainNameLabel $domainNameLabel -EncryptionAtHost;

# Get VM
$vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname;
Assert-AreEqual True $vm.SecurityProfile.encryptionAtHost
Assert-ThrowsContains { Update-AzVM -ResourceGroupName $rgname -VM $vm -EncryptionAtHost $false; } "can be updated only when VM is in deallocated state"

#update vm with encryptionathost false
Stop-AzVM -ResourceGroupName $rgname -Name $vmname -Force;
Update-AzVM -ResourceGroupName $rgname -VM $vm -EncryptionAtHost $false;
$vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname;
Assert-AreEqual False $vm.SecurityProfile.encryptionAtHost

#update vm with encryptionathost false
Update-AzVM -ResourceGroupName $rgname -VM $vm -EncryptionAtHost $true;
$vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname;
Assert-AreEqual True $vm.SecurityProfile.encryptionAtHost
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}
<#
.SYNOPSIS
Test EncryptionAtHost Virtual Machine Default Param Set
#>
function Test-EncryptionAtHostVMDefaultParamSet
{
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
$loc = Get-ComputeVMLocation;
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# VM Profile & Hardware
$vmsize = 'Standard_DS2_v2';
$vmname = 'vm' + $rgname;
$p = New-AzVMConfig -VMName $vmname -VMSize $vmsize -EncryptionAtHost;

# NRP
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
$subnetId = $vnet.Subnets[0].Id;
$pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
$pubip = Get-AzPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
$pubipId = $pubip.Id;
$nic = New-AzNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
$nic = Get-AzNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
$nicId = $nic.Id;

$p = Add-AzVMNetworkInterface -VM $p -Id $nicId;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].Id $nicId;

# Storage Account (SA)
$stoname = 'sto' + $rgname;
$stotype = 'Standard_GRS';
New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
$stoaccount = Get-AzStorageAccount -ResourceGroupName $rgname -Name $stoname;

$osDiskName = 'osDisk';
$osDiskCaching = 'ReadWrite';
$osDiskVhdUri = "https://$stoname.blob.core.windows.net/test/os.vhd";
$dataDiskVhdUri1 = "https://$stoname.blob.core.windows.net/test/data1.vhd";
$dataDiskVhdUri2 = "https://$stoname.blob.core.windows.net/test/data2.vhd";
$dataDiskVhdUri3 = "https://$stoname.blob.core.windows.net/test/data3.vhd";

$p = Set-AzVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption FromImage;

$p = Add-AzVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
$p = Add-AzVMDataDisk -VM $p -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 2 -VhdUri $dataDiskVhdUri2 -CreateOption Empty;
$p = Add-AzVMDataDisk -VM $p -Name 'testDataDisk3' -Caching 'ReadOnly' -DiskSizeInGB 12 -Lun 3 -VhdUri $dataDiskVhdUri3 -CreateOption Empty;
$p = Remove-AzVMDataDisk -VM $p -Name 'testDataDisk3';

Assert-AreEqual $p.StorageProfile.OSDisk.Caching $osDiskCaching;
Assert-AreEqual $p.StorageProfile.OSDisk.Name $osDiskName;
Assert-AreEqual $p.StorageProfile.OSDisk.Vhd.Uri $osDiskVhdUri;
Assert-AreEqual $p.StorageProfile.DataDisks.Count 2;
Assert-AreEqual $p.StorageProfile.DataDisks[0].Caching 'ReadOnly';
Assert-AreEqual $p.StorageProfile.DataDisks[0].DiskSizeGB 10;
Assert-AreEqual $p.StorageProfile.DataDisks[0].Lun 1;
Assert-AreEqual $p.StorageProfile.DataDisks[0].Vhd.Uri $dataDiskVhdUri1;
Assert-AreEqual $p.StorageProfile.DataDisks[1].Caching 'ReadOnly';
Assert-AreEqual $p.StorageProfile.DataDisks[1].DiskSizeGB 11;
Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 2;
Assert-AreEqual $p.StorageProfile.DataDisks[1].Vhd.Uri $dataDiskVhdUri2;

# OS & Image
$user = "Foo12";
$password = $PLACEHOLDER;
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
$computerName = 'test';
$vhdContainer = "https://$stoname.blob.core.windows.net/test";
$img = 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201503.01-en.us-127GB.vhd';

# $p.StorageProfile.OSDisk = $null;
$p = Set-AzVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred;

Assert-AreEqual $p.OSProfile.AdminUsername $user;
Assert-AreEqual $p.OSProfile.ComputerName $computerName;
Assert-AreEqual $p.OSProfile.AdminPassword $password;

# Image Reference
$imgRef = Get-DefaultCRPImage -loc $loc;
$p = ($imgRef | Set-AzVMSourceImage -VM $p);

$p.StorageProfile.DataDisks = $null;

# Virtual Machine
New-AzVM -ResourceGroupName $rgname -Location $loc -VM $p;
$vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname;
Assert-AreEqual True $vm.SecurityProfile.encryptionAtHost

# Remove
Remove-AzVM -ResourceGroupName $rgname -Name $vmname -Force;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Test Set-AzVMOperatingSystem
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
- Additional information about change #1
-->
## Upcoming Release
* Added '-EncryptionAtHost' parameter to New-AzVm, New-AzVmss, New-AzVMConfig, New-AzVmssConfig, Update-AzVM, and Update-AzVmss
* Added 'SecurityProfile' to Get-AzVM and Get-AzVmss return object
* Added the '-InstanceView' switch as optional parameter to Get-AzHostGroup


## Version 4.2.1
* Added warning when using `New-AzVmss` without "latest" image version.
* Added `-Location` as optional positional parameter to `Get-AzComputeResourceSku` cmdlet.
* Added `-PatchMode` as optional parameter to `Set-AzVMOperatingSystem` cmdlet.
* Added warning when using `New-AzVmss` without "latest" image version
* Added '-Location' as optional positional parameter to Get-AzComputeResourceSku cmdlet

## Version 4.2.0
* Added SimulateEviction parameter to Set-AzVM and Set-AzVmssVM cmdlets.
Expand Down
2 changes: 1 addition & 1 deletion src/Compute/Compute/Compute.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PsModuleName>Compute</PsModuleName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public string ResourceGroupName
public string Type { get; set; }
public string Location { get; set; }
public IDictionary<string, string> Tags { get; set; }
public PSVirtualMachineScaleSetVMProfile VirtualMachineProfile { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso
ValueFromPipelineByPropertyName = true)]
public string[] IdentityId { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true)]
public SwitchParameter EncryptionAtHost { get; set; }

protected override void ProcessRecord()
{
if (ShouldProcess("VirtualMachineScaleSet", "New"))
Expand Down Expand Up @@ -378,6 +383,19 @@ private void Run()
vAutomaticRepairsPolicy.Enabled = this.EnableAutomaticRepair.IsPresent;
}

if (this.EncryptionAtHost.IsPresent)
{
if (vVirtualMachineProfile == null)
{
vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile();
}
if (vVirtualMachineProfile.SecurityProfile == null)
{
vVirtualMachineProfile.SecurityProfile = new SecurityProfile();
}
vVirtualMachineProfile.SecurityProfile.EncryptionAtHost = this.EncryptionAtHost;
}

if (this.IsParameterBound(c => c.AutomaticRepairGracePeriod))
{
if (vAutomaticRepairsPolicy == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ public override void ExecuteCmdlet()
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }


[Parameter(
Mandatory = false)]
public bool EncryptionAtHost { get; set; }

private void BuildPatchObject()
{
if (this.IsParameterBound(c => c.AutomaticOSUpgrade))
Expand Down Expand Up @@ -475,7 +480,6 @@ private void BuildPatchObject()
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.OsProfile.WindowsConfiguration.EnableAutomaticUpdates = this.EnableAutomaticUpdate;
}


if (this.IsParameterBound(c => c.IdentityId))
{
if (this.VirtualMachineScaleSetUpdate == null)
Expand Down Expand Up @@ -1090,6 +1094,23 @@ private void BuildPatchObject()
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.StorageProfile.OsDisk.VhdContainers = this.VhdContainer;
}

if (this.IsParameterBound(c => c.EncryptionAtHost))
{
if (this.VirtualMachineScaleSetUpdate == null)
{
this.VirtualMachineScaleSetUpdate = new VirtualMachineScaleSetUpdate();
}
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile == null)
{
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile = new VirtualMachineScaleSetUpdateVMProfile();
}
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.SecurityProfile == null)
{
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.SecurityProfile = new SecurityProfile();
}
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.SecurityProfile.EncryptionAtHost = this.EncryptionAtHost;
}

if (this.VirtualMachineScaleSetUpdate != null
&& this.VirtualMachineScaleSetUpdate.ProximityPlacementGroup != null
&& string.IsNullOrEmpty(this.VirtualMachineScaleSetUpdate.ProximityPlacementGroup.Id))
Expand Down Expand Up @@ -1700,6 +1721,19 @@ private void BuildPutObject()
this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile.OsDisk.VhdContainers = this.VhdContainer;
}

if (this.IsParameterBound(c => c.EncryptionAtHost))
{
if (this.VirtualMachineScaleSet.VirtualMachineProfile == null)
{
this.VirtualMachineScaleSet.VirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile();
}
if (this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile == null)
{
this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile = new SecurityProfile();
}
this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile.EncryptionAtHost = this.EncryptionAtHost;
}

if (this.VirtualMachineScaleSet != null
&& this.VirtualMachineScaleSet.ProximityPlacementGroup != null
&& string.IsNullOrEmpty(this.VirtualMachineScaleSet.ProximityPlacementGroup.Id))
Expand Down
Loading