Azure ARM JSON template - Add VM to Recovery Services Vault in different Resource Group

后端 未结 3 1083
陌清茗
陌清茗 2020-12-21 14:43

I\'m trying to add the functionality to add the VM to a recovery services vault to my existing Azure ARM JSON template that I use for deployment.

I\'ve used the code

3条回答
  •  庸人自扰
    2020-12-21 15:22

    I've found the answer to this if it's useful to anyone else. As already mentioned the recovery services vault will use the same resource group as defined for the template. To be able to define a different template for the RSV this needs to be done using a nested template.

    I have used the following nested template to replace the recovery services resource in my original post, the resource group required for the recovery services vault is defined by "resourceGroup": "[parameters('nestedTemplateRecoveryServicesResourceGroup')]",

    {
    "apiVersion": "2017-05-10",
            "name": "nestedTemplateRecoveryServices",
            "type": "Microsoft.Resources/deployments",
            "resourceGroup": "[parameters('nestedTemplateRecoveryServicesResourceGroup')]",
            "dependsOn": ["[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"],
            "properties": {
                "mode": "Incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {},
                    "variables": {},
                    "resources": [
                            {
                            "name": "[concat(parameters('existingRecoveryServicesVault'), '/', variables('backupFabric'), '/', variables('v2VmContainer'), concat(parameters('existingVirtualMachinesResourceGroup'),';',parameters('existingVirtualMachines')), '/', variables('v2Vm'), concat(parameters('existingVirtualMachinesResourceGroup'),';',parameters('existingVirtualMachines')))]",
                            "apiVersion": "2016-06-01",
                            "location": "[resourceGroup().location]",
                            "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems",
                            "properties": {
                                "protectedItemType": "[variables('v2VmType')]",
                                "policyId": "[resourceId('Microsoft.RecoveryServices/vaults/backupPolicies',parameters('existingRecoveryServicesVault'),parameters('existingBackupPolicy') )]",
                                "sourceResourceId": "[resourceId(subscription().subscriptionId,parameters('existingVirtualMachinesResourceGroup'),'Microsoft.Compute/virtualMachines',parameters('existingVirtualMachines'))]"
                                }
                            }
                        ]
                    },
                   "parameters": {},
                   "outputs": {}
            }
    }
    

提交回复
热议问题