将门户中的应用程序设置与静态 Web 应用程序的二头肌模板中定义的设置相结合

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

因此,我一直遵循此 Stackoverflow 帖子中的说明,并成功地将 Azure 门户中指定的应用程序设置与通过二头肌模板推送的设置合并到 Azure 函数应用程序。

我现在尝试对 Azure 静态 Web 应用程序执行相同的操作,但无法使其工作。这是我的代码:

资源.bicep

(...)
param staticWebAppName string
param staticWebAppCdnLocation string
param staticWebAppSku string

param applicationInsightsName string
param applicationInsightsLocation string = resourceGroup().location

resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
  name: applicationInsightsName
  location: applicationInsightsLocation
  kind: 'web'
  properties: {
    Application_Type: 'web'
    WorkspaceResourceId: logAnalyticsWorkspace.id
    RetentionInDays: 90
    IngestionMode: 'LogAnalytics'
    publicNetworkAccessForIngestion: 'Enabled'
    publicNetworkAccessForQuery: 'Enabled'
  }
  tags: tags
}

module staticWebAppMod 'staticWebApp.bicep' = {
  name: '${staticWebAppName}-deployment'
  scope: resourceGroup()
  params: {
    name: staticWebAppName
    cdnLocation: staticWebAppCdnLocation
    sku: staticWebAppSku
    applicationInsightsId: applicationInsights.id
    applicationInsightsInstrumentationKey: applicationInsights.properties.InstrumentationKey
    applicationInsightsConnectionString: applicationInsights.properties.ConnectionString
    tags: tags
  }
}

(...)

staticWebApp.bicep

param name string
param cdnLocation string
param sku string
param applicationInsightsId string
param applicationInsightsInstrumentationKey string
param applicationInsightsConnectionString string
param tags object

resource staticWebApp 'Microsoft.Web/staticSites@2023-01-01' = {
  name: name
  location: cdnLocation
  sku: {
    name: sku
    size: sku
  }
  properties: {}
  identity: {
    type: 'SystemAssigned'
  }
  tags: staticWebAppTags
}

var currentAppSettings = list(resourceId('Microsoft.Web/staticSites', staticWebApp.name, 'config', 'appsettings'), '2022-09-01').properties

module staticWebAppSettingsMod 'staticWebAppSettings.bicep' = {
  name: 'staticWebAppSettings-deployment}'
  params: {
    staticWebAppName: staticWebApp.name
    currentAppSettings: currentAppSettings
    newAppSettings: {
      APPINSIGHTS_INSTRUMENTATIONKEY: applicationInsightsInstrumentationKey
      APPLICATIONINSIGHTS_CONNECTION_STRING: applicationInsightsConnectionString
    }
  }
}

staticWebAppSettings.bicep

param staticWebAppName string
param currentAppSettings object
param newAppSettings object

resource staticWebAppSettings 'Microsoft.Web/staticSites/config@2022-09-01' = {
  name: '${staticWebAppName}/appsettings'
  properties: union(currentAppSettings, newAppSettings)
}

当我尝试部署上面的代码时,我的 CD 管道中出现以下错误:

{"status":"Failed","error":{"code":"DeploymentFailed","target":"/subscriptions/***/providers/Microsoft.Resources/deployments/main","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.","details":[{"code":"ResourceDeploymentFailure","target":"/subscriptions/***/resourceGroups/***/providers/Microsoft.Resources/deployments/resource-deployment","message":"The resource write operation failed to complete successfully, because it reached terminal provisioning state 'Failed'.","details":[{"code":"DeploymentFailed","target":"/subscriptions/***/resourceGroups/***/providers/Microsoft.Resources/deployments/resource-deployment","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.","details":[{"code":"ResourceDeploymentFailure","target":"/subscriptions/***/resourceGroups/***/providers/Microsoft.Resources/deployments/***","message":"The resource write operation failed to complete successfully, because it reached terminal provisioning state 'Failed'.","details":[{"code":"DeploymentFailed","target":"/subscriptions/***/resourceGroups/***/providers/Microsoft.Resources/deployments/***","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.","details":[{"code":"BadRequest","message":""}]}]}]}]}]}}

请注意,为了便于阅读,省略了 main.bicep 和其他一些不相关的内容。

我错过了什么?

azure azure-resource-manager azure-bicep azure-static-web-app
1个回答
0
投票

不太确定,但这对我有用:使用

listAppSettings
函数。

appsettings.bicep
文件:

param appName string
param appSettings object
param currentAppSettings object

resource app 'Microsoft.Web/staticSites@2023-01-01' existing = {
  name: appName
}

resource appsettings 'Microsoft.Web/staticSites/config@2023-01-01' = {
  parent: app
  name: 'appsettings'
  properties: union(currentAppSettings, appSettings)
}

以及主模板:

param location string = 'East Asia'
param appName string = 'thomasteststatic002'
param skuName string = 'Free'
param skuTier string = 'Free'

// Create the webapp
resource app 'Microsoft.Web/staticSites@2023-01-01' = {
  name: appName
  location: location
  sku: {
    name: skuName
    tier: skuTier
  }
  properties: {}
}

// Create-Update the webapp app settings.
module appSettings 'appsettings.bicep' = {
  name: '${appName}-appsettings'
  params: {
    appName: app.name
    // Get the current appsettings
    currentAppSettings: app.listAppSettings().properties
    appSettings: {
      Foo: 'Bar'
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.