0

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

得到错误为

找不到可用性集“/subscriptions/XXXXXXXXXXX/resourceGroups/XXXXXXXXXXXX/providers/Microsoft.Compute/availabilitySets/XXXXXXX”。

但是它可以在门户网站上使用。我可以手动部署虚拟机。

{
    "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]"
        }
    }
}
4

1 回答 1

0

如果你想将 vm 添加到现有的可用性集 - 你必须给它它的 resourceId,也就是说。将以下参数添加到 vm 属性:

"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

于 2019-02-17T09:40:47.183 回答