json - Azure ARM JSON 模板 - 将 VM 添加到不同资源组中的恢复服务保管库

标签 json azure

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

我使用了以下 GitHub 模板中的代码,如果恢复服务保管库与虚拟机位于同一资源组中,则该代码有效,但如果位于不同的资源组中,则无效。

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()])]"
        }
    }
]

}

没有变量或参数来定义恢复服务保管库资源组。

我还查看了以下 GitHub 模板,该模板也将虚拟机添加到恢复服务保管库,但这似乎无法使用不同的资源组。

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

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

谢谢

最佳答案

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

我使用以下嵌套模板来替换原始帖子中的恢复服务资源,恢复服务保管库所需的资源组由“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": {}
        }
}

关于json - Azure ARM JSON 模板 - 将 VM 添加到不同资源组中的恢复服务保管库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43884921/

相关文章:

azure - 检查 Azure 上不活动的策略

Azure 媒体服务直播延迟

带有变量的 JSON 对象到 PostgreSQL

javascript - 我怎样才能用纯javascript获取ajax请求的ContentType?

azure - Helm 不接受 YAML 值

c# - 如何通过 C# 代码检查 Azure IoT 中心门户中 IoT 设备的状态(启用或禁用)?

azure - 如何在 Windows Azure 上使用 NTP 验证本地 VM 时钟?

mysql - 如何使用正则表达式在mysql中搜索JSON数据

sql - 如何将 JSON 映射到 SQL 架构?

json - curl:JSON 中的意外标记