Error creating auto-scaling rule for app service using terraform in azure
V

1

11
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"
  }
}}   

I tried setting an auto scaling rule in terraform on azure. While doing so it threw this error. kindly help with this. What is this error and how can this error be solved?

Error : Error creating AutoScale Setting "AutoscaleSetting" (Resource Group "sm-prod-resources"): insights.AutoscaleSettingsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="UnsupportedMetric" Message="Exception of type 'Microsoft.WindowsAzure.Management.Monitoring.MonitoringServiceException' was thrown."

Vincents answered 1/11, 2019 at 9:48 Comment(2)
Can you post up your terraform resource block from your tf file?Yeast
Any more questions? Does it solve your problem? Please let me know whatever the state is.Sarsenet
S
15

The error shows that it's an UnsupportedMetric. According to the document in Terraform, it describes like this:

metric_name - (Required) The name of the metric that defines what the rule monitors, such as Percentage CPU for Virtual Machine Scale Sets and CpuPercentage for App Service Plan.

I think it's just a mistake you made, the name with "Percentage CPU" is for Virtual Machine Scale Sets, you need to change it into "CpuPercentage", it's for App Service Plan as you want. For details, see metric_name.

Sarsenet answered 5/11, 2019 at 9:20 Comment(4)
@Vincents Well, then please accept it as the answer.Sarsenet
@Vincents Why not accept my answer when it solved your problem? You just need to click the button, this is no difficulty.Sarsenet
I had the exact same problem. Locally, I was able to run terraform plan with no issues by having the metric names "ScaleIn" and "ScaleOut". But when I would run terraform apply within the pipeline, it would failCalif
@Calif Maybe you can add a new question with mew details.Sarsenet

© 2022 - 2024 — McMap. All rights reserved.