简体   繁体   English

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

[英]Azure ARM Template Deployment in existing Availability Set

From the template below how do I add it to an existing Availability Set(Same resource group). 从下面的模板中,如何将其添加到现有的可用性集(同一资源组)中。 I can't do this after VM creation so I need to do it here. 创建虚拟机后无法执行此操作,因此需要在此处执行。

Getting error as 错误越来越

The Availability Set '/subscriptions/XXXXXXXXXXX/resourceGroups/XXXXXXXXXXXX/providers/Microsoft.Com pute/availabilitySets/XXXXXXX' cannot be found. 找不到可用性集“ /subscriptions/XXXXXXXXXXX/resourceGroups/XXXXXXXXXXXX/providers/Microsoft.Com pute / availabilitySets / XXXXXXX”。

However it is available on portal. 但是,它在门户网站上可用。 I can deploy VM manually. 我可以手动部署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]"
        }
    }
}

if you want to add vm to existing availabilty set - you have to give it its resourceId, that is. 如果要将虚拟机添加到现有可用性集,则必须为其提供resourceId。 add the following parameter to vm properties: 在虚拟机属性中添加以下参数:

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

example: 例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM