0

The intermittent issue where Terraform is unable to create scaling rules on the virtual machine scale-sets because the metrics it requires for the rules are not found.

The issue is usually fixed by rerunning the deployment, but is there a way I can ensure the terraform code waits until the metric has been emitted by the dependent VM before creating the scaling rule?

The following error is thrown in Terraform (version 0.14.8):

Error: Error creating AutoScale Setting "Nuance Speech autoscale Setting - Percentage CPU" (Resource Group "rg-dev-eastus2-nuance"): insights.AutoscaleSettingsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="{"code":"BadRequest","message":"The requested metric defintions 'used_percent' were not found on '/subscriptions/XXX/resourceGroups/rg-dev-eastus2-nuance/providers/Microsoft.Compute/virtualMachineScaleSets/vmss-speech-XX' in namespace 'telegraf/mem'."}"

on .terraform/modules/nuance_speech_linux_vmss_autoscale_rule/main.tf line 1, in resource "azurerm_monitor_autoscale_setting" "this_autoscale_setting": 2022-10-10T17:06:55.240Z [WARN] plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing" 1: resource "azurerm_monitor_autoscale_setting" "this_autoscale_setting" {

Ehsan HP
  • 456
  • 2
  • 5
  • 16
donal
  • 163
  • 2
  • 4
  • 13

1 Answers1

0

I tried to reproduce the same in my environment.

  • Used used_percent metric in the assigned arguments and got the similar error.

enter image description here

  • please visit Supported metrics with Azure Monitor.

  • Percentage CPU can be used Virtual Machine Scale Sets which gives the percentage of allocated compute units that are currently in use by the Virtual Machine and CpuPercentage for App Service Plan.

  • With “Percentage CPU” as metric, I could create scaling rules on the virtual machine scale-sets successfully and have terraform provider version 3.x.x .

    resource "azurerm_monitor_autoscale_setting" "example" {
    name                = "myAutoscaleSetting"
    resource_group_name = data.azurerm_resource_group.example.name
    location            = data.azurerm_resource_group.example.location
    target_resource_id  = azurerm_linux_virtual_machine_scale_set.example.id
    profile {
      name = "defaultProfile"
    
      capacity {
        default = 1
        minimum = 1
        maximum = 10
      }
    
      rule {
        metric_trigger {
          metric_name        = "Percentage CPU"
          metric_resource_id = azurerm_linux_virtual_machine_scale_set.example.id
          time_grain         = "PT1M"
          statistic          = "Average"
          time_window        = "PT5M"
          time_aggregation   = "Average"
          operator           = "GreaterThan"
          threshold          = 75
          metric_namespace   = "microsoft.compute/virtualmachinescalesets"
          dimensions {
            name     = "AppName"
            operator = "Equals"
            values   = ["App1"]
          }
        }
    
        scale_action {
          direction = "Increase"
          type      = "ChangeCount"
          value     = "1"
          cooldown  = "PT1M"
        }
      }
    
      rule {
        metric_trigger {
          metric_name        = "Percentage CPU"
          metric_resource_id = azurerm_linux_virtual_machine_scale_set.example.id
          time_grain         = "PT1M"
          statistic          = "Average"
          time_window        = "PT5M"
          time_aggregation   = "Average"
          operator           = "LessThan"
          threshold          = 25
        }
    
        scale_action {
          direction = "Decrease"
          type      = "ChangeCount"
          value     = "1"
          cooldown  = "PT1M"
        }
      }
    }
    

    }

enter image description here

kavyaS
  • 8,026
  • 1
  • 7
  • 19