You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform创建Azure Dashboard异常:执行成功但UI无实例

Terraform创建Azure Dashboard成功但UI不显示的问题修复

问题分析

你的Terraform代码执行成功,但Azure控制台看不到Dashboard,核心问题是dashboard_properties的JSON格式存在两个关键错误:

  • JSON语法不完整:多个括号未正确闭合,导致生成的JSON结构无效
  • 缺少Azure Dashboard UI渲染必需的metadata顶层属性

修复后的代码

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resource"
  location = "West US 2"
}

resource "azurerm_dashboard" "example" {
  name                = "example-dashboard"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location

  dashboard_properties = jsonencode({
    "metadata": {
      "model": {
        "timeRange": {
          "value": {
            "relative": {
              "duration": "PT1H",
              "timeRangeType": "LastHour"
            }
          },
          "type": "MsPortalFx.Composition.Configuration.ValueTypes.TimeRange"
        },
        "filters": {
          "value": {}
        }
      }
    },
    "lenses": {
      "0": {
        "order": 1,
        "parts": {
          "0": {
            "position": {
              "x": 0,
              "y": 0,
              "rowSpan": 1,
              "colSpan": 1
            },
            "settings": {
              "type": "azuresharedmetric",
              "resourceId": "/subscriptions/xxxx/resourceGroups/example-resource/providers/Microsoft.Compute/virtualMachines/dash",
              "metrics": [
                {
                  "name": "Percentage CPU",
                  "aggregation": "Average"
                }
              ],
              "timeAggregation": "Average"
            }
          }
        }
      }
    }
  })

  tags = {
    environment = "example"
  }
}

关键修复点

  • 补全所有缺失的JSON闭合括号,确保语法合法
  • 添加metadata字段:包含时间范围等基础配置,这是Azure UI识别并渲染Dashboard的必需项
  • 将resource_group_name改为引用资源组的输出属性,避免硬编码不一致的问题

执行修复后的代码并重新运行terraform apply后,即可在Azure UI对应资源组下看到创建的Dashboard。

内容的提问来源于stack exchange,提问作者Nevin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 05:38:17