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

Bicep脚本合并对象去冗余:复用应用服务通用配置

可以实现,具体方案如下

Bicep支持使用**展开运算符(...)**合并对象,刚好能满足你复用通用配置的需求,以下是具体实现方式:

1. 定义通用配置变量

先把重复的通用设置统一定义成一个变量,注意修正你示例里的语法错误(Bicep变量用=而非:,同时注意拼写common而非commom):

var commonSettings = {
  COMMON_CONFIG1: common1
  COMMON_CONFIG2: common2
}

2. 在App Service配置中注入通用设置

在每个Microsoft.Web/sites/config资源的properties字段里,用...commonSettings展开通用配置对象,它会自动将通用键值对合并到当前配置中:

// 第一个App Service的应用配置
resource appSettings1 'Microsoft.Web/sites/config@2022-03-01' = {
  parent: appService1
  name: 'appsettings'
  properties: {
    CONFIG1: value1
    CONFIG2: value2
    ...commonSettings // 注入通用配置
  }
}

// 第二个App Service的应用配置
resource appSettings2 'Microsoft.Web/sites/config@2022-03-01' = {
  parent: appService2
  name: 'appsettings'
  properties: {
    CONFIG3: value3
    CONFIG4: value4
    ...commonSettings // 注入通用配置
  }
}

补充说明

如果某个App Service的配置里定义了和通用配置同名的键(比如COMMON_CONFIG1),本地定义的值会覆盖通用配置中的对应值,本地配置优先级更高。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 13:33:10