Search code examples
azureazure-web-app-serviceazure-resource-managerazure-app-service-plansazure-bicep

How to deploy windows Azure App Service with .Net stack using Bicep?


I've created a Bicep to deploy Service Plan and App Service with linux/windows selection and .net 6 stack. Both deployments successful, Linux App is totally fine, .net 6 stack is present on Portal. However, Windows stack is empty on Portal screen.

I am using the following parameters:

Bicep linux parameter:

  linuxFxVersion: 'DOTNETCORE|6.0'

Bicep Windows parameters:

  windowsFxVersion: 'dotnet:6'
  netFrameworkVersion: 'v6.0'

With this command I get allowed windows stacks, so dotnet:6 should be ok

[ ~ ]$ az webapp list-runtimes --os windows --os-type windows
[
  "dotnet:7",
  "dotnet:6",
  "ASPNET:V4.8",
  "ASPNET:V3.5",
  "NODE:18LTS",
...

I can see with Powershell, that my settings are applied to the Web App.

I've tried different options like dotnet|6, dotnetcore|6 or without netFrameworkVersion and didn't find the right set. Is it Azure interface bug or am I missing something? Thanks in advance, attaching whole Bicep below.

@description('Generate unique String for resource names')
param uniqueFullRGString string = uniqueString(resourceGroup().id)

@description('Short unique name based on RG name')
param uniqueRGString string = take(uniqueFullRGString, 4)

@description('Resource group location')
param location string = resourceGroup().location

@description('Azure Tenant Id')
var azureTenantId = tenant().tenantId

@description('App Service Plan OS')
@allowed([
  'linux'
  'windows'
])
param appServicePlanOS string

var linuxOffer = 'linux'
var windowsOffer = 'windows'

@description('App Service Plan SKU')
param appServicePlanSku string = 'F0'

var configReferenceLinux = {
  linuxFxVersion: 'DOTNETCORE|6.0'
  appSettings: [
    {
      name: 'TenantId'
      value: azureTenantId
    }
  ]
}

var configReferenceWindows = {
  windowsFxVersion: 'dotnet:6'
  netFrameworkVersion: 'v6.0'
  appSettings: [
    {
      name: 'TenantId'
      value: azureTenantId
    }
  ]
}

@description('App Service Plan name')
var appServicePlanName = 'App-${uniqueRGString}'

resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: appServicePlanName
  location: location
  sku: {
    name: appServicePlanSku
  }
  properties: {
      reserved: ((appServicePlanOS == 'linux') ? true : false)
  }
  kind: ((appServicePlanOS == 'linux') ? linuxOffer : windowsOffer)
}

resource appService 'Microsoft.Web/sites@2020-06-01' = {
  name: appServicePlanName
  location: location
  properties: {
    serverFarmId: appServicePlan.id
    siteConfig: ((appServicePlanOS == 'linux') ? configReferenceLinux : configReferenceWindows)
  }
  identity: {
    type: 'SystemAssigned'
  }
}

Solution

  • If you are trying to deploy .NET stack webapp on windows app service plan then you need to add the metadata block which is to define the runtime of your webapp as mentioned in this sample ARM template to create .NET App on windows app service plan.

    I have modified the above shared sample bicep and tested it able to deploy windows app service plan with webapp running on .NET stack.

    @description('Generate unique String for resource names')
    param uniqueFullRGString string = uniqueString(resourceGroup().id)
    
    @description('Short unique name based on RG name')
    param uniqueRGString string = take(uniqueFullRGString, 4)
    
    @description('Resource group location')
    param location string = resourceGroup().location
    
    @description('Azure Tenant Id')
    var azureTenantId = tenant().tenantId
    
    @description('App Service Plan OS')
    @allowed([
      'linux'
      'windows'
    ])
    param appServicePlanOS string
    
    var linuxOffer = 'linux'
    var windowsOffer = 'windows'
    
    @description('App Service Plan SKU')
    param appServicePlanSku string = 'F0'
    
    var configReferenceLinux = {
      linuxFxVersion: 'DOTNETCORE|6.0'
      appSettings: [
        {
          name: 'TenantId'
          value: azureTenantId
        }
      ]
    }
    
    var configReferenceWindows = {
      metadata :[
        {
          name:'CURRENT_STACK'
          value:'dotnet'
        }
      ]
      netFrameworkVersion:'v7.0'
      appSettings: [
        {
          name: 'TenantId'
          value: azureTenantId
        }
      ]
    }
    
    @description('App Service Plan name')
    var appServicePlanName = 'App-${uniqueRGString}'
    
    resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
      name: appServicePlanName
      location: location
      sku: {
        name: appServicePlanSku
      }
      properties: {
          reserved: ((appServicePlanOS == 'linux') ? true : false)
      }
      kind: ((appServicePlanOS == 'linux') ? linuxOffer : windowsOffer)
    }
    
    resource appService 'Microsoft.Web/sites@2020-06-01' = {
      name: appServicePlanName
      location: location
      properties: {
        serverFarmId: appServicePlan.id
        siteConfig: ((appServicePlanOS == 'linux') ? configReferenceLinux : configReferenceWindows)
      }
      identity: {
        type: 'SystemAssigned'
      }
    }
    

    Sample Output Screenshot for reference:

    enter image description here

    You can refer to this similar SO thread as well.