我在 bicep 脚本中定义了多个应用程序服务。对于每一个,我都使用配置资源来定义配置。
resource appSettings1 'Microsoft.Web/sites/config@2022-03-01' = {
parent: appService1
name: 'appsettings'
properties: {
CONFIG1: value1
CONFIG2: value2
COMMON_CONFIG1: commom1
COMMON_CONFIG2: commom2
}
}
resource appSettings2 'Microsoft.Web/sites/config@2022-03-01' = {
parent: appService2
name: 'appsettings'
properties: {
CONFIG3: value3
CONFIG4: value4
COMMON_CONFIG1: commom1
COMMON_CONFIG2: commom2
}
}
应用服务中有很多通用设置。有没有一种方法可以只定义一次公共设置并将它们注入每个配置,这样我就不必在每个应用程序服务中定义相同的设置? 有点像这样:
var commomSettings: {
COMMON_CONFIG1: commom1
COMMON_CONFIG2: commom2
}
resource appSettings1 'Microsoft.Web/sites/config@2022-03-01' = {
parent: appService1
name: 'appsettings'
properties: {
CONFIG1: value1
CONFIG2: value2
...commonSettings //somehow inject commonSettings
}
}
是的,你在正确的轨道上,你可以使用 union 函数来合并对象:
var commomSettings = {
COMMON_CONFIG1: commom1
COMMON_CONFIG2: commom2
}
resource appSettings1 'Microsoft.Web/sites/config@2022-03-01' = {
parent: appService1
name: 'appsettings'
properties: union(commomSettings, {
CONFIG1: value1
CONFIG2: value2
}
)
}