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

如何在Bicep/ARM模板中获取地域的显示名称?

在Bicep/ARM模板中获取地域显示名称的方法

ARM模板实现方式

  • 调用listLocations函数获取目标资源提供商的全地域列表,以Microsoft.Web为例:
    listLocations(resourceId('Microsoft.Web', ''), '2016-06-01')
    
    该调用返回的数组中,每个元素包含name(地域代码,如westus)和displayName(显示名称,如West US)两个核心字段。
  • 通过filter筛选匹配目标地域的项,再用first提取唯一匹配结果,最终获取显示名称。如果需要转为小写(适配你的警报条件格式),可嵌套toLower函数:
    toLower(first(filter(listLocations(resourceId('Microsoft.Web', ''), '2016-06-01'), loc => loc.name == toLower(parameters('location')))).displayName)
    
    将上述表达式直接嵌入警报条件的containsAny数组即可。

Bicep实现方式

Bicep的语法更简洁,可直接通过变量定义完成逻辑:

param location string

// 获取小写格式的地域显示名称
var regionDisplayName = toLower(first(filter(listLocations(resourceId('Microsoft.Web', ''), '2016-06-01'), loc => loc.name == toLower(location))).displayName)

// 定义警报条件
var alertCondition = {
  field: 'properties.impactedServices[*].ImpactedRegions[*].RegionName'
  containsAny: [ regionDisplayName ]
}

原表达式失效原因

你之前使用的listLocations('/subscriptions/${subscriptionId}/providers/Microsoft.Web/locations/${toLower(location)}', '2016-06-01').displayName写法错误:listLocations的第一个参数应为资源提供商的根路径(如/subscriptions/{subscriptionId}/providers/Microsoft.Web),而非单个地域的路径。指定单个地域路径时,函数返回的结构不包含displayName字段,因此无法获取到目标值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 00:55:19