I am using bicep with Azure DevOps to deploy to Azure Web Apps.
I'm struggling to get the connectionString format right and I am being met with the following error from the pipeline log: The parameter properties has an invalid value....
Hoping for some guidance and help..
Pipeline log extract :
{
"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
}
}
]
}
Here are my relevant bicep files:
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
connectionStrings
should be defined directly inside the properties:
resource webappConnectionStrings 'Microsoft.Web/sites/config@2024-04-01' = {
name: 'connectionstrings'
parent: webapp
properties: connectionStrings
}
Same for appSettings
and it should be an object rather than an array:
resource webappsettings 'Microsoft.Web/sites/config@2024-04-01' = {
name: 'appsettings'
parent: webapp
properties: {
'ApiConfiguration:MyProjectAPIKey': MyProjectAPIKey
}
}