Scenario: You want to move an Azure Linux VM from one subscription to another subscription hosted in a different directory. You want to do this using an ARM template.
Assumptions:
i) You already have a VM running on one of the subscriptions.
ii) For the purpose of this tutorial, I am using a VM running Ubuntu which I will be moving. You could be using any other Linux workload.
iii) The source subscription is called X and the target is called Y.
iv) We will use Powershell to deploy the template but you can also use Bash.
Steps:
-
-
- We need to download the ARM template of the VM from the source subscription. Let’s call it subscription X.
- Login to the Azure portal of subscription X.
- Navigate to the VM. Then click on the VM’s Resource Group. On the LHS, click on Automation Script. Then click on Download. It will download a zip.
- Go to the directory where target subscription Y is located.
- Fetch the subscription ID of subscription Y. You can get this by clicking on Overview in any Resource Group and copying subscription Id from there.
- Alternatively, type Get-AzureRMSubscription in the Powershell Cloudshell and copy the subscription ID for subscription Y.
- In the downloaded zip, open template.json and update all the subscription IDs to the one we copied in the previous step.
- If there are any storage accounts in the template.json, update the value to a unique value to avoid errors when running the template. You can search for parameters starting with prefix storageAccounts.
- Upload this template to a storage account on subscription Y. Get its blob URL.
- Create a resource group in the subscription Y. Let’s call it “RG-DEST-VM”
- In the Azure CloudShell, ensure Powershell is selected.
- Make sure you have selected the correct subscription
Select–AzureRmSubscription –SubscriptionId <<ID>>
-
13. Deploy the template using:
-
- New-AzureRmResourceGroupDeployment -ResourceGroupName “RG-DEST-VM” -TemplateUri your-blob-url