在 azure 中使用 terraform 为应用服务创建自动缩放规则时出错

Sid*_*kar 5 azure app-service-environment azure-app-service-plans azure-web-app-service terraform-provider-azure

resource "azurerm_monitor_autoscale_setting" "test" {
  name                = "AutoscaleSetting"
  resource_group_name = "${azurerm_resource_group.main.name}"
  location            = "${azurerm_resource_group.main.location}"
  target_resource_id  = "${azurerm_app_service_plan.main.id}"

 profile {
name = "defaultProfile"

capacity {
  default = 1
  minimum = 1
  maximum = 10
}

rule {
  metric_trigger {
    metric_name        = "Percentage CPU"
    metric_resource_id = "${azurerm_app_service_plan.main.id}"
    time_grain         = "PT1M"
    statistic          = "Average"
    time_window        = "PT5M"
    time_aggregation   = "Average"
    operator           = "GreaterThan"
    threshold          = 80
  }

  scale_action {
    direction = "Increase"
    type      = "ChangeCount"
    value     = "1"
    cooldown  = "PT1M"
  }
}

rule {
  metric_trigger {
    metric_name        = "Percentage CPU"
    metric_resource_id = "${azurerm_app_service_plan.main.id}"
    time_grain         = "PT1M"
    statistic          = "Average"
    time_window        = "PT5M"
    time_aggregation   = "Average"
    operator           = "LessThan"
    threshold          = 80
  }

  scale_action {
    direction = "Decrease"
    type      = "ChangeCount"
    value     = "1"
    cooldown  = "PT1M"
  }
}}   
Run Code Online (Sandbox Code Playgroud)

我尝试在天蓝色的 terraform 中设置自动缩放规则。这样做时它抛出了这个错误。请帮助解决这个问题。这是什么错误,如何解决这个错误?

错误:创建自动缩放设置“AutoscaleSetting”(资源组“sm-prod-resources”)时出错:insights.AutoscaleSettingsClient#CreateOrUpdate:响应请求失败:StatusCode=400 -- 原始错误:autorest/azure:服务返回错误。Status=400 Code="UnsupportedMetric" Message="抛出了“Microsoft.WindowsAzure.Management.Monitoring.MonitoringServiceException”类型的异常。"

Cha*_* Xu 10

该错误表明它是UnsupportedMetric。根据 Terraform 中的文档,它是这样描述的:

metric_name -(必需)定义规则监控内容的指标的名称,例如虚拟机规模集的 CPU 百分比和应用服务计划的 CpuPercentage。

我认为这只是您犯的一个错误,带有“百分比 CPU”的名称是虚拟机规模集的名称,您需要将其更改为“ CpuPercentage ”,这是您想要的应用服务计划。有关详细信息,请参阅metric_name