Azure ARM JSON模板-将VM添加到其他资源组中的Recovery Services Vault [英] Azure ARM JSON template - Add VM to Recovery Services Vault in different Resource Group

查看:93
本文介绍了Azure ARM JSON模板-将VM添加到其他资源组中的Recovery Services Vault的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加功能,以将VM添加到我用于部署的现有Azure ARM JSON模板的恢复服务库中.

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.

我已经使用了以下GitHub模板中的代码,并且如果恢复服务库与VM在同一资源组中,而在不同的资源组中则没有,则此方法有效.

I've used the code from the following GitHub template and this works if the recovery services vault is in the same resource group as VM but not if its in a different one.

https://github .com/Azure/azure-quickstart-templates/tree/master/101-recovery-services-backup-vms

代码如下:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "existingVirtualMachinesResourceGroup": {
        "type": "string",
        "metadata": {
            "description": "Resource group where the virtual machines are located. This can be different than resource group of the vault. "
        }
    },
    "existingVirtualMachines": {
        "type": "array",
        "metadata": {
            "description": "Array of Azure virtual machines. e.g. [\"vm1\",\"vm2\",\"vm3\"]"
        }
    },
    "existingRecoveryServicesVault": {
        "type": "string",
        "metadata": {
            "description": "Recovery services vault name where the VMs will be backed up to. "
        }
    },
    "existingBackupPolicy": {
        "type": "string",
        "defaultValue": "DefaultPolicy",
        "metadata": {
            "description": "Backup policy to be used to backup VMs. Backup POlicy defines the schedule of the backup and how long to retain backup copies. By default every vault comes with a 'DefaultPolicy' which canbe used here."
        }
    }
},
"variables": {
    "backupFabric": "Azure",
    "v2VmType": "Microsoft.Compute/virtualMachines",
    "v2VmContainer": "iaasvmcontainer;iaasvmcontainerv2;",
    "v2Vm": "vm;iaasvmcontainerv2;"
},
"resources": [
    {
        "name": "[concat(parameters('existingRecoveryServicesVault'), '/', variables('backupFabric'), '/', variables('v2VmContainer'), concat(parameters('existingVirtualMachinesResourceGroup'),';',parameters('existingVirtualMachines')[copyIndex()]), '/', variables('v2Vm'), concat(parameters('existingVirtualMachinesResourceGroup'),';',parameters('existingVirtualMachines')[copyIndex()]))]",
        "apiVersion": "2016-06-01",
        "location": "[resourceGroup().location]",
        "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems",
        "copy": {
            "name": "v2VmsCopy",
            "count": "[length(parameters('existingVirtualMachines'))]"
        },
        "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')[copyIndex()])]"
        }
    }
]

}

没有定义恢复服务库资源组的变量或参数.

There is no variable or parameter to define the recovery services vaults resource group.

我还查看了以下GitHub模板,该模板也将VM添加到了恢复服务库中,但同样似乎无法使用其他资源组.

I've also looked at the following GitHub template that also adds a VM to a recovery services vault but again this doesn't seem to have the ability to use different resource groups.

https://github.com/Azure/azure-quickstart-templates/tree/master/201-recovery-services-backup-classic-resource-manager-vms

我已经尝试过谷歌搜索,但到目前为止我还没有找到答案,这有可能吗?

I've tried googling but so far I haven't been able to find an answer to this so is it possible?

谢谢

推荐答案

如果对其他人有用,我已经找到了答案.如前所述,恢复服务库将使用与模板定义的资源组相同的资源组.为了能够为RSV定义其他模板,需要使用嵌套模板来完成.

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.

我在原始帖子中使用了以下嵌套模板替换恢复服务资源,恢复服务库所需的资源组由"resourceGroup"定义:"[[parameters('nestedTemplateRecoveryServicesResourceGroup')]",

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": {}
        }
}

这篇关于Azure ARM JSON模板-将VM添加到其他资源组中的Recovery Services Vault的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆