skip to Main Content

Im trying to setup the appsettings.json varibale in my App service, which can add using the colon mark.

When Im trying to add the appsetting manually it works

App configuration:

App configuration

But when trying to add using the bicep script it fails.

var dbConnectionString = 'test connection'
resource siteconfigWebjob 'Microsoft.Web/sites/config@2022-03-01' = {
  parent: windowsAppService
  name: 'appsettings'
  properties: {
    'ConnectionStrings:DefaultConnection': dbConnectionString
  }
}

I also tried this appSetting config in the App service bicep

resource windowsAppService 'Microsoft.Web/sites@2022-03-01' = {
  name: webjobAppServiceName
  location: resourceGroupLocation
  kind: 'app'
  properties: {
    serverFarmId: windowsappServicePlan.id
    siteConfig: {
      appSettings: [
        {
          name: 'AzureWebJobsStorage'
          value: storageConnectionString
        }
        {
          name: 'MaxCsvFileSizeInBytes'
          value: '4194304'
        }

I want to add the nested configuration to the App settings

2

Answers


  1. Chosen as BEST ANSWER

    I tried this method and it worked for me.

    var defaultConnection = 'DefaultConnection'
    var tenantConnection = 'TenantConnection'
    var applicationInsightConnectionString = 'ApplicationInsightsConnectionString'
    var emailProcessorEndpoint = 'EmailProcessorEndpoint'
    
    
    resource siteconfigWebjob 'Microsoft.Web/sites/config@2022-03-01' = {
      parent: windowsAppService
      name: 'appsettings'
      properties: {
        'ConnectionStrings:${defaultConnection}': dbConnectionString
        'ConnectionStrings:${tenantConnection}': tenantDbConnection
        'ConnectionStrings:${applicationInsightConnectionString}': applicationInsights.properties.ConnectionString
        AzureWebJobsDashboard: storageConnectionString
        AzureWebJobsStorage: storageConnectionString
        MaxCsvFileSizeInBytes: '4194304'
        WebsiteUrl: 'https://${frontendAppServiceName}.azurewebsites.net'
        'EventGridCredentials:${emailProcessorEndpoint}': emailProcessor.properties.endpoint
        
      }
    }
    

  2. When trying to add the app setting using portal also, it is not working for me with colon mark.

    enter image description here

    Basically, the conventional way of naming an app setting name should include only letters, numbers, underscores, periods as highlighted below.

    I have used below notation to name an app setting and also added nested app settings as shown below.

    'ConnectionStrings_DefaultConnection': dbConnectionString

    You can either add an app setting under siteconfig block with Microsoft.Web/sites resource provider or add a separate resource provider called Microsoft.Web/sites/config as detailed below.

    param webApp string = 'xxx'
    param sku string = 'S1'
    param linuxFxVersion string = 'php|7.4'
    param location string = resourceGroup().location
    
    var webAppName = '${webApp}-webapp'
    var appServicePlan = 'AppServicePlan-${webApp}'
    
    
    resource appService 'Microsoft.Web/serverfarms@2022-03-01' = {
      name: appServicePlan
      location: location
      sku: {
        name: sku
      }
      kind: 'linux'
      properties: {
        reserved: true
      }
    }
    resource webAppPortal 'Microsoft.Web/sites@2022-03-01' = {
      name: webAppName
      location: location
      kind: 'app'
      properties: {
        serverFarmId: appService.id
        siteConfig: {
          appSettings: [
            {
              name: 'AzureWebJobsStorage'
              value: 'xxxx'
            }
            {
              name: 'MaxCsvFileSizeInBytes'
              value: '4194304'
            }
            {
              name: 'ConnectionStrings_DefaultConnection'
              value: dbConnectionString
            }
        ]
          linuxFxVersion: linuxFxVersion
          ftpsState: 'FtpsOnly'
        }
        httpsOnly: true
      }
      identity: {
        type: 'SystemAssigned'
      }
    }
    
    var dbConnectionString = 'test connection'
    resource siteconfigWebjob 'Microsoft.Web/sites/config@2022-03-01' = {
      parent: webAppPortal
      name: 'appsettings'
      properties: {
        'ConnectionStrings_DefaultConnection': dbConnectionString
      }
    }
    

    Deployment succeeded:

    enter image description here

    enter image description here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search