From 3949597452975904f4d5b1f5c66569dcab343227 Mon Sep 17 00:00:00 2001 From: Naman Shah Date: Thu, 5 May 2022 12:08:31 +0530 Subject: [PATCH] Adding a new ARM Template for restoring a VM from Restore Point (#8) * Adding a new ARM Template for restoring a VM from Restore Point --- RestoreVMFromRestorePoint.json | 249 +++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 RestoreVMFromRestorePoint.json diff --git a/RestoreVMFromRestorePoint.json b/RestoreVMFromRestorePoint.json new file mode 100644 index 0000000..0e59ba3 --- /dev/null +++ b/RestoreVMFromRestorePoint.json @@ -0,0 +1,249 @@ +{ + "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "" + }, + "networkInterfaceName": { + "type": "string", + "defaultValue": "" + }, + "networkSecurityGroupName": { + "type": "string", + "defaultValue": "" + }, + "subnetName": { + "type": "string", + "defaultValue": "" + }, + "virtualNetworkName": { + "type": "string", + "defaultValue": "" + }, + "publicIpAddressName": { + "type": "string", + "defaultValue": "" + }, + "virtualMachineName": { + "type": "string", + "defaultValue": "" + }, + "virtualMachineComputerName": { + "type": "string", + "defaultValue": "" + }, + "virtualMachineSize": { + "type": "string", + "defaultValue": "" + }, + "adminUsername": { + "type": "string", + "defaultValue": "" + }, + "adminPassword": { + "type": "secureString", + "defaultValue": "" + }, + "osdiskRestorePointResourceId": { + "type": "string", + "defaultValue": "/subscriptions//resourceGroups//providers/Microsoft.Compute/restorePointCollections//restorePoints//diskRestorePoints/" + }, + "datadiskRestorePointResourceId": { + "type": "string", + "defaultValue": "/subscriptions//resourceGroups//providers/Microsoft.Compute/restorePointCollections//restorePoints//diskRestorePoints/" + }, + "restoredOSDiskName": { + "type": "string", + "defaultValue": "" + }, + "restoredOSDiskSku": { + "type": "string", + "defaultValue": "Premium_LRS" + }, + "restoredOSDiskSizeGB": { + "type": "string", + "defaultValue": "1024" + }, + "restoredDataDiskName": { + "type": "string", + "defaultValue": "" + }, + "restoredDataDiskSku": { + "type": "string", + "defaultValue": "Premium_LRS" + }, + "restoredDataDiskSizeGB": { + "type": "string", + "defaultValue": "1024" + } + }, + "variables": { + "nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]", + "vnetName": "[parameters('virtualNetworkName')]", + "vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]", + "subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]", + "restoredOSDiskResourceId": "[resourceId(resourceGroup().name, 'Microsoft.Compute/disks', parameters('restoredOSDiskName'))]", + "restoredDataDiskResourceId": "[resourceId(resourceGroup().name, 'Microsoft.Compute/disks', parameters('restoredDataDiskName'))]" + }, + "resources": [ + { + "apiVersion": "2021-04-01", + "type": "Microsoft.Compute/disks", + "name": "[parameters('restoredOSDiskName')]", + "location": "[parameters('location')]", + "properties": { + "creationData": { + "createOption": "Restore", + "sourceResourceId": "[parameters('osdiskRestorePointResourceId')]" + }, + "diskSizeGB": "[parameters('restoredOSDiskSizeGB')]" + }, + "sku": { + "name": "[parameters('restoredOSDiskSku')]" + } + }, + { + "apiVersion": "2021-04-01", + "type": "Microsoft.Compute/disks", + "name": "[parameters('restoredDataDiskName')]", + "location": "[parameters('location')]", + "properties": { + "creationData": { + "createOption": "Restore", + "sourceResourceId": "[parameters('datadiskRestorePointResourceId')]" + }, + "diskSizeGB": "[parameters('restoredDataDiskSizeGB')]" + }, + "sku": { + "name": "[parameters('restoredDataDiskSku')]" + } + }, + { + "name": "[parameters('networkInterfaceName')]", + "type": "Microsoft.Network/networkInterfaces", + "apiVersion": "2021-03-01", + "location": "[parameters('location')]", + "dependsOn": [ + "[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]", + "[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]", + "[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName'))]" + ], + "properties": { + "ipConfigurations": [ + { + "name": "ipconfig1", + "properties": { + "subnet": { + "id": "[variables('subnetRef')]" + }, + "privateIPAllocationMethod": "Dynamic", + "publicIpAddress": { + "id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName'))]", + "properties": { + "deleteOption": "Detach" + } + } + } + } + ], + "networkSecurityGroup": { + "id": "[variables('nsgId')]" + } + } + }, + { + "name": "[parameters('networkSecurityGroupName')]", + "type": "Microsoft.Network/networkSecurityGroups", + "apiVersion": "2019-02-01", + "location": "[parameters('location')]", + "properties": { + "securityRules": [ + ] + } + }, + { + "name": "[parameters('virtualNetworkName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2020-11-01", + "location": "[parameters('location')]", + "properties": { + "addressSpace": { + "addressPrefixes": [ + "10.0.0.0/16" + ] + }, + "subnets": [ + { + "name": "default", + "properties": { + "addressPrefix": "10.0.0.0/24" + } + } + ] + } + }, + { + "name": "[parameters('publicIpAddressName')]", + "type": "Microsoft.Network/publicIpAddresses", + "apiVersion": "2020-08-01", + "location": "[parameters('location')]", + "properties": { + "publicIpAllocationMethod": "Dynamic" + }, + "sku": { + "name": "Basic" + } + }, + { + "name": "[parameters('virtualMachineName')]", + "type": "Microsoft.Compute/virtualMachines", + "apiVersion": "2021-07-01", + "location": "[parameters('location')]", + "dependsOn": [ + "[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]", + "[concat('Microsoft.Compute/disks/', parameters('restoredOSDiskName'))]", + "[concat('Microsoft.Compute/disks/', parameters('restoredDataDiskName'))]" + ], + "properties": { + "hardwareProfile": { + "vmSize": "[parameters('virtualMachineSize')]" + }, + "storageProfile": { + "osDisk": { + "osType": "Windows", + "createOption": "attach", + "managedDisk": { + "id": "[variables('restoredOSDiskResourceId')]" + } + }, + "datadisks": [ + { + "lun": 0, + "createOption": "attach", + "managedDisk": { + "id": "[variables('restoredDataDiskResourceId')]" + } + } + ] + }, + "networkProfile": { + "networkInterfaces": [ + { + "id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]", + "properties": { + "deleteOption": "Detach" + } + } + ] + }, + "diagnosticsProfile": { + "bootDiagnostics": { + "enabled": true + } + } + } + } + ] +} \ No newline at end of file