question

JasonPeterson-8094 avatar image
0 Votes"
JasonPeterson-8094 asked JasonPeterson-8094 edited

How can I assign the Virtual Network durring a deployment via the Azure CLI?

I am restoring a backup from one resource group to another, both the disks and the VM. I am able to restore everything to the new resource group, however, the new VM is attached to the old resource groups Virtual Network.

I am trying to replicate the functionality of the portal see the attached screen shot.

123978-screen-shot-2021-08-17-at-122805-pm.png



One can select the Resource Group and Virtual Network to assign to the restored VM. How can I do this via the CLI Interface?

Here is my current command:

az deployment group create --subscription $subscription --resource-group $toResourceGroup --name $vnetName --template-uri "$url?$token" --no-wait --parameters VirtualMachineName=$toVMName

azure-virtual-network
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JasonPeterson-8094 avatar image
0 Votes"
JasonPeterson-8094 answered JasonPeterson-8094 edited

Actually I was able to replicate the portal functions with "--parameters" by following:

https://docs.microsoft.com/en-us/cli/azure/backup/restore?view=azure-cli-latest

And then adding the "VirtualMachineName", "VirtualNetwork", and "VirtualNetworkResourceGroup" params / overrides.

 az deployment group create \ 
 --subscription $subscription \ 
 --resource-group $toResourceGroup \ 
 --name $restoreName \ 
 --template-uri "$url?$token" \ 
 --parameters VirtualMachineName=$restoreVMName \ 
 --parameters VirtualNetwork=$vnetName \ 
 --parameters VirtualNetworkResourceGroup=$toResourceGroup 

Hope this helps anyone else, thank you!





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

suvasara-MSFT avatar image
0 Votes"
suvasara-MSFT answered suvasara-MSFT edited

@JasonPeterson-8094, I have reproduced this in my lab and found that there is no direct CLI command to achieve this. Actually, there two types of restoration,
1.create new VM and restore from the available RP's. (Possible from portal / indirectly can be achieved using modified Rest API JSON format in CLI )
2.Replace the existing one. (Azure Doc provided)

Procedure:
1. Follow this document, take a backup.
2. create a storage account and restore the disk data to the container.
3. Now you will be holding three files in your storage account,
124849-image.png

In which, deploy.json file is used to set the dynamic parameter while deploying a template. Change the necessary parameters in that file and redeploy it for the desired configuration.

 az deployment group create \
   --name ExampleDeployment \
   --resource-group ExampleGroup \
   --template-file storage.json \
   --parameters '@storage.parameters.json'

Like in the above provided example. You need to deploy your template with necessary parameters. Also, i am leaving a reference document for you to get more insights about deploying resources with ARM templates and Azure CLI.



Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.



image.png (13.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.