簡體   English   中英

無法使用 ARM 模板為我的 VMSS 模板計划創建自動縮放屬性

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

我正在嘗試創建 ARM 模板,以使用上述模板作為參考,在資源中添加縮放屬性,如下所示。 已創建其他資源,但 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'))]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM