无法使用 ARM 模板为我的 VMSS 模板计划创建自动缩放 属性

Not able to create autoscale in and out property for my VMSS template plan using ARM template

我正在尝试创建 ARM 模板以根据以下使用上述模板作为参考在 Resources 中添加缩放 属性。已创建其他资源,但 ARM 无法在我的 VMSS 模板中创建任何类型的自动缩放组。

{
            "type": "microsoft.insights/autoscalesettings",
            "apiVersion": "2015-04-01",
            "name": "AutoScaleSet",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Compute/virtualMachineScaleSets/', parameters('VMSS_Name'))]"
            ],
            "properties": {
                "name": "autoscalehost",
                "targetResourceUri": "[resourceId('Microsoft.Compute/virtualMachineScaleSets/', parameters('VMSS_Name'))]",
                "enabled": true,
                "profiles": [
                    {
                        "name": "autoscalehost",
                        "capacity": {
                            "minimum": "1",
                            "maximum": "3",
                            "default": "1"
                        },
                        "rules": [
                            {
                                "metricTrigger": {
                                    "metricName": "Percentage CPU",
                                    "metricResourceUri": "[concat('Microsoft.Compute/virtualMachineScaleSets', parameters('VMSS_Name'))]",
                                    "timeGrain": "PT1M",
                                    "statistic": "Average",
                                    "timeWindow": "PT5M",
                                    "timeAggregation": "Average",
                                    "operator": "GreaterThan",
                                    "threshold": 50
                                },
                                "scaleAction": {
                                    "direction": "Increase",
                                    "type": "ChangeCount",
                                    "value": "1",
                                    "cooldown": "PT5M"
                                }
                            },
                            {
                                "metricTrigger": {
                                    "metricName": "Percentage CPU",
                                    "metricResourceUri": "[concat('Microsoft.Compute/virtualMachineScaleSets', parameters('VMSS_Name'))]",
                                    "timeGrain": "PT1M",
                                    "statistic": "Average",
                                    "timeWindow": "PT5M",
                                    "timeAggregation": "Average",
                                    "operator": "LessThan",
                                    "threshold": 30
                                },
                                "scaleAction": {
                                    "direction": "Decrease",
                                    "type": "ChangeCount",
                                    "value": "1",
                                    "cooldown": "PT5M"
                                }
                            }
                        ]
                    }
                ]
            }
        }

我可以在这里看到两个不同的问题:

1) 自动缩放设置的名称在一个位置是 'AutoScaleSet',在另一个位置是 'autoscalehost':

    {
          "type": "microsoft.insights/autoscalesettings",
          "apiVersion": "2015-04-01",
HERE -->  "name": "AutoScaleSet",             
          "location": "[parameters('location')]",
          "dependsOn": [
            "[resourceId('Microsoft.Compute/virtualMachineScaleSets/', parameters('VMSS_Name'))]"
          ],
          "properties": {
HERE -->    "name": "autoscalehost",
            "targetResourceUri": "[resourceId('Microsoft.Compute/virtualMachineScaleSets/', parameters('VMSS_Name'))]",
            "enabled": true
          }

这需要是相同的值,否则部署会失败并出现以下错误:

{
  "code": "BadRequest",
  "message": "The autoscale setting that you provided does not have the same name as the name in the request. Name in autoscale setting: autoscalehost. Name in the request: AutoScaleSet"
}

2) 没有向 metricTrigger 规则提供正确的资源 ID

  {
    "metricTrigger": {
    "metricName": "Percentage CPU",
--> "metricResourceUri": "[concat('Microsoft.Compute/virtualMachineScaleSets', parameters('VMSS_Name'))]", <--
    "timeGrain": "PT1M"
  }

您需要此处的完整资源 ID。不仅提供者名称 + VMSS 名称。否则部署将失败并出现以下错误:

{
  "code": "LinkedInvalidPropertyId",
  "message": "Property id 'Microsoft.Compute/virtualMachineScaleSetssotest' is invalid. Expect fully qualified resource Id that start with '/subscriptions/{subscriptionId}' or '/providers/{resourceProviderNamespace}/'."
}

在您的模板中使用 resourceId() 函数代替 concat(),如下所示:

[resourceId('Microsoft.Compute/virtualMachineScaleSets/', parameters('VMSS_Name'))]