@@ -443,11 +443,13 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
443443 string targetVNetResourceGroup = ( string ) ProviderData [ RestoreVMBackupItemParams . TargetVNetResourceGroup ] ;
444444 string targetSubnetName = ( string ) ProviderData [ RestoreVMBackupItemParams . TargetSubnetName ] ;
445445 string targetSubscriptionId = ( string ) ProviderData [ RestoreVMBackupItemParams . TargetSubscriptionId ] ;
446-
446+
447447 Dictionary < UriEnums , string > uriDict = HelperUtils . ParseUri ( rp . Id ) ;
448448 string containerUri = HelperUtils . GetContainerUri ( uriDict , rp . Id ) ;
449449
450- GenericResource storageAccountResource = ServiceClientAdapter . GetStorageAccountResource ( storageAccountName ) ;
450+ if ( targetSubscriptionId == null || targetSubscriptionId == "" ) targetSubscriptionId = ServiceClientAdapter . SubscriptionId ;
451+
452+ GenericResource storageAccountResource = ServiceClientAdapter . GetStorageAccountResource ( storageAccountName , targetSubscriptionId ) ;
451453
452454 var useOsa = ShouldUseOsa ( rp , osaOption ) ;
453455
@@ -496,7 +498,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
496498 {
497499 identityInfo = new IdentityInfo ( ) ;
498500 if ( useSystemAssignedIdentity )
499- {
501+ {
500502 identityInfo . IsSystemAssignedIdentity = true ;
501503 }
502504 else
@@ -511,12 +513,10 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
511513 }
512514 else
513515 {
514- throw new NotSupportedException ( Resources . MSIRestoreNotSupportedForUnmanagedVM ) ;
516+ throw new NotSupportedException ( Resources . MSIRestoreNotSupportedForUnmanagedVM ) ;
515517 }
516518 }
517-
518- string targetSubscription = ( targetSubscriptionId != null && targetSubscriptionId != "" ) ? targetSubscriptionId : ServiceClientAdapter . SubscriptionId ;
519-
519+
520520 IaasVMRestoreRequest restoreRequest = new IaasVMRestoreRequest ( )
521521 {
522522 CreateNewCloudService = false ,
@@ -525,7 +525,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
525525 Region = vaultLocation ?? ServiceClientAdapter . BmsAdapter . GetResourceLocation ( ) ,
526526 StorageAccountId = storageAccountResource . Id ,
527527 SourceResourceId = rp . SourceResourceId ,
528- TargetResourceGroupId = targetResourceGroupName != null ? "/subscriptions/" + targetSubscription + "/resourceGroups/" + targetResourceGroupName : null ,
528+ TargetResourceGroupId = targetResourceGroupName != null ? "/subscriptions/" + targetSubscriptionId + "/resourceGroups/" + targetResourceGroupName : null ,
529529 OriginalStorageAccountOption = useOsa ,
530530 RestoreDiskLunList = restoreDiskLUNS ,
531531 DiskEncryptionSetId = DiskEncryptionSetId ,
@@ -562,8 +562,8 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
562562 }
563563
564564 restoreRequest . RecoveryType = RecoveryType . AlternateLocation ;
565- restoreRequest . TargetVirtualMachineId = "/subscriptions/" + targetSubscription + "/resourceGroups/" + targetResourceGroupName + "/providers/Microsoft.Compute/virtualMachines/" + targetVMName ;
566- restoreRequest . VirtualNetworkId = "/subscriptions/" + targetSubscription + "/resourceGroups/" + targetVNetResourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + targetVNetName ;
565+ restoreRequest . TargetVirtualMachineId = "/subscriptions/" + targetSubscriptionId + "/resourceGroups/" + targetResourceGroupName + "/providers/Microsoft.Compute/virtualMachines/" + targetVMName ;
566+ restoreRequest . VirtualNetworkId = "/subscriptions/" + targetSubscriptionId + "/resourceGroups/" + targetVNetResourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + targetVNetName ;
567567 restoreRequest . SubnetId = restoreRequest . VirtualNetworkId + "/subnets/" + targetSubnetName ;
568568 }
569569
0 commit comments