Skip to content

Add new optional parameter SecuredVMOsDiskEncryptionSetId in Restore-AzRecoveryServicesBackupItem #28203

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -87,7 +87,8 @@ public enum RestoreVMBackupItemParams
TargetSubscriptionId,
RestoreToEdgeZone,
DiskAccessOption,
TargetDiskAccessId
TargetDiskAccessId,
CVMOsDiskEncryptionSetId
}

public enum RestoreFSBackupItemParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()

Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
string containerUri = HelperUtils.GetContainerUri(uriDict, rp.Id);
string cVMOsDiskEncryptionSetId = ProviderData.ContainsKey(RestoreVMBackupItemParams.CVMOsDiskEncryptionSetId) ?
ProviderData[RestoreVMBackupItemParams.CVMOsDiskEncryptionSetId].ToString() : null;

if (targetSubscriptionId == null || targetSubscriptionId == "") targetSubscriptionId = ServiceClientAdapter.SubscriptionId;

Expand Down Expand Up @@ -647,6 +649,11 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
}
}

if (!string.IsNullOrWhiteSpace(cVMOsDiskEncryptionSetId))
{
restoreRequest.SecuredVMDetails = new SecuredVMDetails(cVMOsDiskEncryptionSetId);
}

if (restoreType == "OriginalLocation") // replace existing
{
restoreRequest.RecoveryType = RecoveryType.OriginalLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,17 @@ public void TestAzurePERestore()
"Test-AzurePERestore"
);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(TestConstants.Workload, TestConstants.AzureVM)]
public void TestAzureRestoreWithCVMOsDiskEncryptionSetId()
{
TestRunner.RunTestScript(
$"Import-Module {_IaasVmcommonModule.AsAbsoluteLocation()}",
$"Import-Module {_IaasVmtestModule.AsAbsoluteLocation()}",
"Test-AzureRestoreWithCVMOsDiskEncryptionSetId"
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1332,3 +1332,62 @@ function Test-AzureVMDiskExclusion
cleanup-ResourceGroup $resourceGroupName
}
}

function Test-AzureRestoreWithCVMOsDiskEncryptionSetId()
{
$location = "eastus2euap"
$resourceGroupName = "sgholap-rg"
$vaultName = "PSTestingVault"
$vmName = "PSCVMRestoreTestingVM"
$saName = "sgholapecysa3"
$targetVMName = "PSRestoreVM"
$targetVNetName = "testadeecy-vnet"
$targetRG = "asmaskarrg"
$targetSubnetName = "default"
$owner = "sgholap"
$subscriptionId = "5288acd1-ba79-4377-9205-9f220331a44a"
$recoveryPointId = "807152782396876"
$cVMOSDiskEncryptionSetId = "/subscriptions/5288acd1-ba79-4377-9205-9f220331a44a/resourceGroups/sgholap-rg/providers/Microsoft.Compute/diskEncryptionSets/CVMPSRestoreDES"
try
{
# Setup
$vault = Get-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName
$namedContainer = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -FriendlyName $vmName -VaultId $vault.ID
$backupitem = Get-AzRecoveryServicesBackupItem -Container $namedContainer -WorkloadType "AzureVM" -VaultId $vault.ID
$rp = Get-AzRecoveryServicesBackupRecoveryPoint -Item $backupitem -VaultId $vault.ID -RecoveryPointId $recoveryPointId

# Test command by passing CVMOSDiskEncryptionSetId as non-empty string
$restoreJob = Restore-AzRecoveryServicesBackupItem -VaultId $vault.ID -VaultLocation $vault.Location `
-RecoveryPoint $rp[0] -StorageAccountName $saName -StorageAccountResourceGroupName $vault.ResourceGroupName -TargetResourceGroupName $targetRG -TargetVMName $targetVMName -TargetVNetName $targetVNetName -TargetVNetResourceGroup $targetRG -TargetSubnetName $targetSubnetName -CVMOSDiskEncryptionSetId $cVMOSDiskEncryptionSetId

$restoreJob = $restoreJob | Wait-AzRecoveryServicesBackupJob -VaultId $vault.ID

Assert-True { $restoreJob.Status -eq "Completed" }

Delete-VM $targetRG $targetVMName

# Test command by passing CVMOSDiskEncryptionSetId as empty string
$cVMOSDiskEncryptionSetId = ""

$restoreJob = Restore-AzRecoveryServicesBackupItem -VaultId $vault.ID -VaultLocation $vault.Location `
-RecoveryPoint $rp[0] -StorageAccountName $saName -StorageAccountResourceGroupName $vault.ResourceGroupName -TargetResourceGroupName $targetRG -TargetVMName $targetVMName -TargetVNetName $targetVNetName -TargetVNetResourceGroup $targetRG -TargetSubnetName $targetSubnetName -CVMOSDiskEncryptionSetId $cVMOSDiskEncryptionSetId

$restoreJob = $restoreJob | Wait-AzRecoveryServicesBackupJob -VaultId $vault.ID

Assert-True { $restoreJob.Status -eq "Completed" }

Delete-VM $targetRG $targetVMName

# Test command without passing CVMOSDiskEncryptionSetId
$restoreJob = Restore-AzRecoveryServicesBackupItem -VaultId $vault.ID -VaultLocation $vault.Location `
-RecoveryPoint $rp[0] -StorageAccountName $saName -StorageAccountResourceGroupName $vault.ResourceGroupName -TargetResourceGroupName $targetRG -TargetVMName $targetVMName -TargetVNetName $targetVNetName -TargetVNetResourceGroup $targetRG -TargetSubnetName $targetSubnetName

$restoreJob = $restoreJob | Wait-AzRecoveryServicesBackupJob -VaultId $vault.ID

Assert-True { $restoreJob.Status -eq "Completed" }
}
finally
{
Delete-VM $targetRG $targetVMName
}
}
Loading