Bicep:避免 appSettings 中的冗余

问题描述 投票:0回答:1

我在 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
  }
}
azure azure-resource-manager azure-appservice azure-bicep
1个回答
0
投票

是的,你在正确的轨道上,你可以使用 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
    }
  )
}
© www.soinside.com 2019 - 2024. All rights reserved.