现有可用性集中的Azure ARM模板部署

时间:2019-02-17 09:37:33

标签: azure azure-resource-manager azure-availability-set

如何从下面的模板中将其添加到现有的可用性集(同一资源组)中。创建虚拟机后无法执行此操作,因此需要在此处执行。

获取错误

  

可用性集   '/subscriptions/XXXXXXXXXXX/resourceGroups/XXXXXXXXXXXX/providers/Microsoft.Com   找不到pute / availabilitySets / XXXXXXX'。

但是,它在门户网站上可用。我可以手动部署VM。

{
    "contentVersion": "1.0.0.0",
    "parameters": {
        SOME MORE PARAMETERS
        "AvSet":{
            "type": "string",
            "defaultValue": "XXXXXXXXXXXXX"
        },

    },
    "variables": {
        "ExtensionLink": "[concat(parameters('containerUrl'),'/domainjoin_extension.json')]",
        "subnetRef": "[resourceId(parameters('existingVnetResourceGroup'), 'Microsoft.Network/virtualNetworks/subnets', parameters('existingVnetName'),  parameters('existingSubnetName'))]",

    },
    "resources": [{
            "type": "Microsoft.Compute/virtualMachines",
            "name": "[parameters('virtualMachineName')]",
            "apiVersion": "2017-03-30",
            "location": "[resourceGroup().location]",
            "tags": "[parameters('tagValues')]",
            "properties": {
                "osProfile": {
                    "computerName": "[parameters('virtualMachineName')]",
                    "adminUsername": "[parameters('adminUsername')]",
                    "adminPassword": "[parameters('adminPassword')]"
                },
                "hardwareProfile": {
                    "vmSize": "[parameters('virtualMachineSize')]"
                },
                "storageProfile": {
                    "imageReference": {
                        "publisher": "[parameters('publisher')]",
                        "offer": "[parameters('offer')]",
                        "sku": "[parameters('OSVersion')]",
                        "version": "latest"
                    },
                    "osDisk": {
                        "createOption": "fromImage",
                        "diskSizeGB": "[parameters('diskSizeGB')]",
                        "managedDisk": {
                            "storageAccountType": "[parameters('storageAccountType')]"
                        },
                        "name": "[parameters('osDiskName')]"
                    }

                },
                "networkProfile": {
                    "networkInterfaces": [{
                        "id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
                    }]
                },

                "diagnosticsProfile": {
                    "bootDiagnostics": {
                        "enabled": true,
                        "storageUri": "[reference(resourceId(parameters('existingStorageRgName'), 'Microsoft.Storage/storageAccounts', parameters('existingDiagnosticsStorageAccountName')), '2015-06-15').primaryEndpoints['blob']]"
                    }
                },
                "AvailabilitySet" : {
                  "id": "[resourceId('Microsoft.Compute/availabilitySets', parameters('AvSet'))]"
                },
            },

            "dependsOn": [
                "[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]",

            ]
        },

        {
            "type": "Microsoft.Network/networkInterfaces",
            "name": "[parameters('networkInterfaceName')]",
            "apiVersion": "2016-09-01",
            "location": "[resourceGroup().location]",
            "tags": "[parameters('tagValues')]",
            "properties": {

                "ipConfigurations": [{
                    "name": "ipconfig1",
                    "properties": {
                        "subnet": {
                            "id": "[variables('subnetRef')]"
                        },
                        "privateIPAllocationMethod": "Dynamic"
                    }
                }]
            }
        },
        {
            "apiVersion": "2017-05-10",
            "name": "linked1",
            "condition": "[equals(parameters('extensionCreateorNot'),'yes')]",
            "type": "Microsoft.Resources/deployments",
            "properties": {
                "mode": "incremental",
                "templateLink": {
                    "uri": "[variables('ExtensionLink')]",
                    "contentVersion": "1.0.0.0"
                },
                "parameters": {
                    "virtualMachineName": {
                        "value": "[string(parameters('virtualMachineName'))]"
                    },
                    "domainJoinUserName": {
                        "value": "[string(parameters('domainJoinUserName'))]"
                    },
                    "domainJoinUserPassword": {
                        "value": "[string(parameters('domainJoinUserPassword'))]"
                    },
                    "domainFQDN": {
                        "value": "[string(parameters('domainFQDN'))]"
                    },
                    "ouPath": {
                        "value": "[string(parameters('ouPath'))]"
                    }

                }

            },
            "dependsOn": [
                "linked2",
                "[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]",
                "[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"

            ]
        },
        {
            "apiVersion": "2017-05-10",
            "name": "linked2",
            "condition": "[equals(parameters('dataDisksattachornot'),'yes')]",
            "type": "Microsoft.Resources/deployments",
            "properties": {
                "mode": "incremental",
                "templateLink": {
                    "uri": "[variables('attachDataDiskExtensionLink')]",
                    "contentVersion": "1.0.0.0"
                },
                "parameters": {
                    "virtualMachineName": {
                        "value": "[string(parameters('virtualMachineName'))]"
                    },
                    "sizeOfDataDisksInGB": {
                        "value": "[array(parameters('sizeOfDataDisksInGB'))]"
                    },
                    "tagValues": {
                        "value": "[parameters('tagValues')]"
                    }
                }
            },
            "dependsOn": [
                "[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]",
                "[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
            ]
        }
    ],
    "outputs": {
        "adminUsername": {
            "type": "String",
            "value": "[parameters('adminUsername')]"
        },
        "virtualMachineName": {
            "type": "String",
            "value": "[parameters('virtualMachineName')]"
        },
        "networkInterface": {
            "type": "string",
            "value": "[reference(concat(parameters('networkInterfaceName'))).ipConfigurations[0].properties.privateIPAddress]"
        }
    }
}

1 个答案:

答案 0 :(得分:0)

如果要将虚拟机添加到现有可用性集,则必须为其提供resourceId。在虚拟机属性中添加以下参数:

"availabilitySet": {
    "id": "[resourceId('Microsoft.Compute/availabilitySets', 'existing_availability_set_name')]"
},

示例:

https://github.com/Azure/azure-quickstart-templates/blob/master/201-2-vms-loadbalancer-natrules/azuredeploy.json#L264