0
votes

Is it possible to create a Virtual Machine (Ubuntu Linux) in Azure using ARM template, where I will store the .vhd file in a storage account and while deploying in a separate Azure resource group (Client) the storage account will be accessed using access keys to deploy the VM.

I used the below command to copy the VHD to a storage account in my RG.

az storage blob copy ​ start ​ --destination-blob​ $destinationVHDFileName
--destination-container​ $storageContainerName ​ --account-name​ $storageAccountName
--account-key​ $storageAccountKey ​ --source-uri​ $sas 
1

1 Answers

1
votes

If you want to create a Vm with your own vhd file, you can create an Azure managed image with the VHD file then create VM with the image. For more details, please refer to here and here

For example

  1. Create Azure managed image
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "images_testimage_name": {
            "defaultValue": "testimage1",
            "type": "String"
        },
       "blobUri": {
            "defaultValue": "<your vhd file url>",
            "type": "String"
        },
       "location": {
            "defaultValue": "",
            "type": "String"
        }

    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Compute/images",
            "apiVersion": "2019-07-01",
            "name": "[parameters('images_testimage_name')]",
            "location": "[parameters('location')]",
            "properties": {
                "storageProfile": {
                    "osDisk": {
                        "osType": "Linux",
                        "osState": "Generalized",
                        "diskSizeGB": 30,
                        "blobUri": "[parameters('blobUri')]",
                        "caching": "ReadWrite",
                        "storageAccountType": "Premium_LRS"
                    },
                    "dataDisks": [],
                    "zoneResilient": true
                },
                "hyperVGeneration": "V1"
            }
        }
    ]
}
  1. Create VM
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
},
    "variables": {},
    "resources": [
     ... other resource
        {
            "name": "[parameters('virtualMachineName')]",
            "type": "Microsoft.Compute/virtualMachines",
            "apiVersion": "2020-06-01",
            "location": "[parameters('location')]",
            
            "properties": {
                "hardwareProfile": {
                    "vmSize": "[parameters('virtualMachineSize')]"
                },
                "storageProfile": {
                    "osDisk": {
                        "createOption": "fromImage",
                        "managedDisk": {
                            "storageAccountType": "Premium_LRS"
                        }
                    },
                    "imageReference": {
                        "id": "<the resource id of the image you create in step1>"
                    }
                },
                ... other configurations
            }
        }
    ]
}