使用Bicep部署Azure Web Apps遇properties参数无效错误求助
问题:Azure Web Apps连接字符串部署失败(The parameter properties has an invalid value)
部署Azure Web Apps时,连接字符串配置始终失败,管道日志返回错误:The parameter properties has an invalid value...
错误日志
{ "code": "DeploymentFailed", "target": ".../myproject-webapp-be", "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", "target": "/subscriptions/GUID-HERE/resourceGroups/rg-my-project/providers/Microsoft.Web/sites/my-backend/config/connectionstrings", "message": { "Code": "BadRequest", "Message": "The parameter properties has an invalid value.", "Target": null, "Details": [ { "Message": "The parameter properties has an invalid value." }, { "Code": "BadRequest" }, { "ErrorEntity": { "ExtendedCode": "51008", "MessageTemplate": "The parameter {0} has an invalid value.", "Parameters": [ "properties" ], "Code": "BadRequest", "Message": "The parameter properties has an invalid value." } } ], "Innererror": null } } ] }
相关Bicep代码
main.bicep
param locationID string = resourceGroup().id param locationName string = resourceGroup().location param tags object = {} @secure() param dbConnectionStringMyProject string @secure() param connectionStringAzureStorage string @secure() param MyProjectAPIKey string module asp 'modules/app-service-plan.bicep' = { name: 'myproject-asp' params: { appServicePlanName: 'my-asp' locationName: locationName tags: tags } } module webappbe 'modules/app-service.bicep' = { name: 'myproject-webapp-be' params: { locationID: locationID locationName: locationName appServicePlanID: asp.outputs.appServicePlanID appServiceAppName: 'my-backend' tags: tags appSettings: [ { name: 'ApiConfiguration:MyProjectAPIKey' value: MyProjectAPIKey } ] connectionStrings: { 'DBConnectionSqlServer': { value: dbConnectionStringMyProject type: 'SQLAzure' } 'AzureStorage': { value: connectionStringAzureStorage type: 'Custom' } } } } module webappfe 'modules/app-service.bicep' = { name: 'myproject-webapp-fe' params: { locationID: locationID locationName: locationName appServicePlanID: asp.outputs.appServicePlanID appServiceAppName: 'my-frontend' tags: tags appSettings: [ { name: 'ApiConfiguration:MyProjectAPIKey' value: MyProjectAPIKey } ] connectionStrings: { 'DBConnectionSqlServer': { value: dbConnectionStringMyProject type: 'SQLAzure' } } } dependsOn: [ webappbe ] }
modules/app-service.bicep
type NameValuePair = { name: string value: string } param locationName string param locationID string param appServicePlanID string param appServiceAppName string param tags object = {} param appSettings NameValuePair[] = [] param connectionStrings object = {} resource webapp 'Microsoft.Web/sites@2023-01-01' = { name: appServiceAppName location: locationName kind: 'windows' identity: { type: 'SystemAssigned' } tags: union( tags, { 'hidden-related:${locationID}/providers/Microsoft.Web/serverfarms/appServicePlan': 'Resource' } ) properties: { serverFarmId: appServicePlanID httpsOnly: true siteConfig: { keyVaultReferenceIdentity: 'SystemAssigned' publicNetworkAccess: 'Enabled' alwaysOn: true minTlsVersion: '1.2' use32BitWorkerProcess: false webSocketsEnabled: true vnetRouteAllEnabled: true netFrameworkVersion: 'v9.0' cors: { allowedOrigins: ['*'] } } } } resource webappsettings 'Microsoft.Web/sites/config@2023-01-01' = { name: 'web' parent: webapp properties: { appSettings: appSettings } } resource webappConnectionStrings 'Microsoft.Web/sites/config@2024-04-01' = { name: 'connectionstrings' parent: webapp properties: { connectionStrings: connectionStrings } } output appServiceHostName string = webapp.properties.defaultHostName
解决方案
问题出在modules/app-service.bicep中的连接字符串资源配置:Azure Web Apps的connectionstrings配置资源,其properties字段需要直接传入连接字符串的键值对对象,不需要额外嵌套一层connectionStrings属性。
修改webappConnectionStrings资源的定义:
resource webappConnectionStrings 'Microsoft.Web/sites/config@2024-04-01' = { name: 'connectionstrings' parent: webapp properties: connectionStrings // 直接传入参数,不再嵌套 }
额外验证点
- 确认连接字符串的
type值为Azure支持的有效值:SQLAzure、Custom、SQLServer、MySQL等,你的配置中使用的SQLAzure和Custom是正确的。 - 建议保持资源API版本一致(当前Web App用2023-01-01,连接字符串用2024-04-01,虽然不影响功能,但统一版本更易维护)。
内容的提问来源于stack exchange,提问作者Sha
相关产品推荐
相关产品推荐

