gpt4 book ai didi

azure - 是否有解决方法可以保留 Bicep 模板中未定义的应用程序设置?

转载 作者:行者123 更新时间:2023-12-02 22:50:01 26 4
gpt4 key购买 nike

main.bicep


resource appService 'Microsoft.Web/sites@2020-06-01' = {
name: webSiteName
location: location
properties: {
serverFarmId: appServicePlan.id
siteConfig: {
linuxFxVersion: linuxFxVersion

appSettings: [
{
name: 'ContainerName'
value: 'FancyContainer'
}
{
name: 'FancyUrl'
value: 'fancy.api.com'
}
]
}
}
}

基础结构发布过程成功运行,并且应用程序设置设置正确,之后我运行节点应用程序构建和发布,其中 Azure DevOps 发布管道将一些与应用程序相关的配置添加到应用程序设置。 (例如 API key 、API URL),一切都运行良好。

但是,如果我必须重新发布基础架构,例如,我使用存储帐户扩展我的环境,则应用程序发布设置的应用程序设置将会丢失。

是否有解决方法可以保留 Bicep 模板中未定义的应用设置?

最佳答案

摘自这篇文章:Merge App Settings With Bicep .

  1. 部署时请勿在 siteConfig 中包含 appSettings
  2. 创建一个模块来创建/更新应用设置,将现有设置与新设置合并。

appsettings.bicep 文件:

param webAppName string
param appSettings object
param currentAppSettings object

resource webApp 'Microsoft.Web/sites@2022-03-01' existing = {
name: webAppName
}

resource siteconfig 'Microsoft.Web/sites/config@2022-03-01' = {
parent: webApp
name: 'appsettings'
properties: union(currentAppSettings, appSettings)
}

main.bicep:

param webAppName string
...

// Create the webapp without appsettings
resource webApp 'Microsoft.Web/sites@2022-03-01' = {
name: webAppName
...
properties:{
...
siteConfig: {
// Dont include the appSettings
}
}
}

// Create-Update the webapp app settings.
module appSettings 'appsettings.bicep' = {
name: '${webAppName}-appsettings'
params: {
webAppName: webApp.name
// Get the current appsettings
currentAppSettings: list(resourceId('Microsoft.Web/sites/config', webApp.name, 'appsettings'), '2022-03-01').properties
appSettings: {
Foo: 'Bar'
}
}
}

关于azure - 是否有解决方法可以保留 Bicep 模板中未定义的应用程序设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72940236/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com