Azure / Terraform - azurerm_monitor_autoscale_setting 具有存储队列

Azure / Terraform - azurerm_monitor_autoscale_setting with storage queues

我想创建一个规则来在队列中的消息数量大于某个值时扩展应用程序服务计划。

队列定义如下所示:

resource "azurerm_storage_queue" "myqueue" {
  name                 = "myqueue"
  storage_account_name = "storageaccountname"
}

缩放规则如下所示:

    rule {
      metric_trigger {
        metric_name        = "ApproximateMessageCount"
        metric_resource_id = azurerm_storage_queue.myqueue.id
        time_grain         = "PT1M"
        statistic          = "Average"
        time_window        = "PT1M"
        time_aggregation   = "Average"
        operator           = "GreaterThanOrEqual"
        threshold          = 100
      }

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

问题出在 metric_resource_id - 我不确定它需要什么属性或 ID。错误信息是 The number of path segments is not divisible by 2。我相信这是因为队列的 id 只是它的名称,而 resource_id 应该类似于 /subscriptions/xxxxxxx/resourceGroups/xxxxxx/providers/Microsoft.Storage/storageAccounts/storageaccountname/services/queue/queues/myqueue" 但我不确定如何从 terraform.

azurerm_storage_queue.myqueue.id 的输出是 Url 格式 https://storageaccountname.queue.core.windows.net/mysamplequeue

metric_resource_id 需要发出指标的资源的资源 ID。据我所知,我们无法直接从 Terraform 资源属性获取资源格式,但我们可以 self-construct 将资源 ID

metric_resource_id = join("/",["${azurerm_storage_account.example.id}","services/queue/queues","mysamplequeue"])

例如,

rule {
  metric_trigger {
    metric_name        = "ApproximateMessageCount"
    metric_resource_id = join("/",["${azurerm_storage_account.example.id}","services/queue/queues","myqueue"])
    time_grain         = "PT1M"
    statistic          = "Average"
    time_window        = "PT5M"
    time_aggregation   = "Average"
    operator           = "GreaterThanOrEqual"
    threshold          = 100
  }