Failed to create the Azure Autoscale Setting service

Description

Hello, I am trying to add a Custom autoscale setting based on CPU for Machine Scale Set Azure but i am having the following error :

Error: Error creating AutoScale Setting "scale-test" (Resource Group "MyResourceGroup"): insights.AutoscaleSettingsClient#CreateOrUpdate: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>

Affected Resource(s)

  • azurerm_monitor_autoscale_setting

Terraform version

try it with :

  • terraform 11
  • terraform 12
  • terraform 13

Terraform Configuration Files


resource "azurerm_virtual_machine_scale_set" "vmss" {
}

resource "azurerm_monitor_autoscale_setting" "vmss" {
  name                = "scale-test"
  resource_group_name = "${var.resource_group_name}"
  location            = "${var.location}"
  target_resource_id  = azurerm_virtual_machine_scale_set.vmss.id
  tags                = "${var.default_tags}"

  profile {
    name = "CpuProfile"

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

    rule {
      metric_trigger {
        metric_name        = "Percentage CPU"
        metric_resource_id = azurerm_virtual_machine_scale_set.vmss.id
        time_grain         = "PT1M"
        statistic          = "Average"
        time_window        = "PT5M"
        time_aggregation   = "Average"
        operator           = "GreaterThan"
        threshold          = 85
      }

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

    rule {
      metric_trigger {
        metric_name        = "Percentage CPU"
        metric_resource_id = azurerm_virtual_machine_scale_set.vmss.id
        time_grain         = "PT1M"
        statistic          = "Average"
        time_window        = "PT5M"
        time_aggregation   = "Average"
        operator           = "LessThan"
        threshold          = 20
      }

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

  # notification {
  #   email {
  #     send_to_subscription_administrator    = true
  #     send_to_subscription_co_administrator = true
  #   }
  # }
}

Expected Behavior

Creating my custom autoscale setting for my Machine Scale Set Azure service

Steps to Reproduce

terraform init
terraform plan

Can someone, help me please ?