azureazure-web-app-serviceazure-resource-managerazure-bicep

Setting a server minimum for Azure Web App when using automatic scaling, from Bicep


I have an Azure web app that I want to use the automatic scaling for, but guarantee that there's at least 2 instances running.

I've removed a buch of extraneous data and renamed things, but my resources for the app service and web app look like this:

resource mySite 'Microsoft.Web/sites@2023-12-01' = {
  name: mySiteName
  location: resourceGroupLocation
  properties: {
    serverFarmId: serverfarm.id
    httpsOnly: true
    siteConfig: {
      netFrameworkVersion: 'v8.0'
      minimumElasticInstanceCount: 2
    }
  }
}
resource serverfarm 'Microsoft.Web/serverfarms@2023-12-01' = {
  name: serverfarmName
  location: resourceGroupLocation
  kind: 'windows'
  sku: {
    tier: 'Premium'
    name: 'P0v3'
  }
  properties: {
    elasticScaleEnabled: true
    maximumElasticWorkerCount: 10
  }
}

However when I deploy this, I only have a single instance running. I can change it in the portal using the "Always Ready Instances" slider, and this seems to work fine. If I use the "JSON View" of the resource to see what has changed, then only the setting that has changed is the "minimumElasticInstanceCount" that I'm trying to set in the Bicep file.

Is there a way to achieve what I'm trying here?


Solution

  • Changing the kind property to app with same template worked for me.

    You can refer to this wiki for more information: App Service Kind property

    param resourceGroupLocation string = resourceGroup().location
    param serverfarmName string = 'thomastestappserviceplan1234'
    param mySiteName string = 'thomastestwebapp1234'
    
    resource serverfarm 'Microsoft.Web/serverfarms@2023-12-01' = {
      name: serverfarmName
      location: resourceGroupLocation
      kind: 'app'
      sku: {
        tier: 'Premium'
        name: 'P0v3'
      }
      properties: {
        elasticScaleEnabled: true
        maximumElasticWorkerCount: 10
      }
    }
    
    resource mySite 'Microsoft.Web/sites@2023-12-01' = {
      name: mySiteName
      location: resourceGroupLocation
      kind: 'app'
      properties: {
        serverFarmId: serverfarm.id
        httpsOnly: true
        siteConfig: {
          netFrameworkVersion: 'v8.0'
          minimumElasticInstanceCount: 2
        }
      }
    }