Coder Perfect

How to configure Runtime Stack to Azure App Service with Bicep (Bicep version 0.4)

Problem

Using the current Bicep Version 0.4, I was able to construct an App Service Plan and App Service.

resource myAppServicePlan 'Microsoft.Web/serverfarms@2021-01-01'={
name: AppServicePlanName
location: Location
sku: {
 name: appServicePlanSkuName
 tier: AppServiceTier
 }  
}
resource myAppService 'Microsoft.Web/sites@2021-01-01'={
  name: AppServiceName
  location: Location
  properties:{
  serverFarmId: myAppServicePlan.id
  }
 }

The framework version is set to ASP.NET 4.8 by default. I’d like to use Netcore 3.1 with the Framework. Is there a way to make that happen yet?

Please suggest. Thank you. Praveen

Asked by Prawin

Solution #1

No matter what bicep version you have, you may adjust it simply adding the proper option to the resource. It’s LinuxFxVersion for Linux plans, which is the same as ARM but has a distinct writing syntax. More information can be found in the app service documentation: https://docs.microsoft.com/en-us/azure/app-service/quickstart-arm-template

If you’re having trouble figuring out which property to set in bicep/ARM, open developer tools in your browser and examine the POST message sent by Portal to management.azure.com, or go to resources.azure.com and look at the details of a resource that has already been configured (via Portal), or use the export template functionality.

Edit: Setting up the runtime stack for the Windows App Service Plan is a little tricky. There’s a property called netFrameworkVersion that can be v3.0, v4.0, or v5.0.

To get to the core, though, It appears that you must work with metadata in sites/config:

resource myAppService 'Microsoft.Web/sites@2021-01-01' = {
  name: AppServiceName
  location: Location
  properties:{
  serverFarmId: myAppServicePlan.id
  }

  resorce 'webConfig' config = {
    name: 'web'
    properties: {
      metadata: [
      {
        name: 'CURRENT_STACK'
        value: 'dotnetcore'
      }
      ]
    }
  }
}

Set the value to dotnet and use the netFrameworkVersion property if you want to go back to.NET or switch to.NET5 (and then.NET6).

The netFrameworkVersion appears to be disregarded when CURRENT STACK is set to dotnetcore.

This information was gleaned via watching PUT requests, which are what portals do when they change the stack. I’m not sure what possibilities there are for setting up other stacks, such as Java or PHP. CURRENT STACK + other properties in sites/config ‘web’ are probably used in a similar way.

There doesn’t appear to be any documentation about this.

BTW, do not utilize it within the Microsoft.Web/Sites resource; instead, use the Microsoft.web/sites/config with web name. Although I could utilize such settings via the siteConfig field in the past, the resource provider API did not set them.

Answered by Miq

Post is based on https://stackoverflow.com/questions/67823980/bicep-how-to-config-runtime-stack-to-azure-app-service-bicep-version-0-4