azureazure-functionsazure-bicepazure-app-service-plans

Unable to deploy flex consumption function app using azure bicep


resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = {
  name: 'vvkstaccforflexfuncapp'  
  location: 'uksouth'
  kind: 'StorageV2'
  sku: {
    name: 'Standard_LRS'
  }
  properties: {
    accessTier: 'Hot'
    minimumTlsVersion: 'TLS1_2'
  }
}


resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
  name: 'name'
  location: 'uksouth'
  kind: 'web'
  properties: {
    Application_Type: 'web'
  }
}

resource virtualNetwork 'Microsoft.Network/virtualNetworks@2019-11-01' = {
  name: 'vnetforflexfuncapp'
  location: 'uksouth'
  properties: {
    addressSpace: {
      addressPrefixes: [
        '10.0.0.0/16'
      ]
    }
    subnets: [
      {
        name: 'InboundSubnet'
        properties: {
          addressPrefix: '10.0.0.0/24'
        }
      }
      {
        name: 'OutboundSubnet'
        properties: {
          addressPrefix: '10.0.1.0/24'
        }
      }
    ]
  }
}


resource flexappserviceplan 'Microsoft.Web/serverfarms@2024-04-01' = {
  name: 'vscodeflexappserviceplan'
  location:  'uksouth'
  sku: {
    name: 'FC1'
    tier: 'FlexConsumption'
    family: 'FC'
    capacity: 0
  }
  kind: 'functionapp'
}

resource flexfunapp 'Microsoft.Web/sites@2024-04-01' = {
  name: 'vscodeflexfunapp'
  location: 'uksouth'
  kind: 'functionapp,linux'
  properties: {
    serverFarmId: flexappserviceplan.id
    siteConfig: {
      appSettings: [
        {
          name: 'AzureWebJobsStorage__accountName'
          value: storageAccount.name
        }
        {
          name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
          value: appInsights.properties.ConnectionString
        }
      ]
      numberOfWorkers: 1
    }
    functionAppConfig: {
      deployment: {
        storage: {
          type: 'blobcontainer'
          value: '${storageAccount.properties.primaryEndpoints.blob}container'
          authentication: {
            type: 'SystemAssignedIdentity'
          }
          
        }
      }
      scaleAndConcurrency: {
        maximumInstanceCount: 100
        instanceMemoryMB: 4096
      }
      runtime: {
        name: 'python'
        version: '3.11'
      }
    }
    httpsOnly: true
    publicNetworkAccess: 'Disabled'
    virtualNetworkSubnetId: '/subscriptions/subscriptionid/resourceGroups/vivekchak-rg/providers/Microsoft.Network/virtualNetworks/vnetforflexfuncapp/subnets/OutboundSubnet'    
  }
}

resource privateEndpoint1 'Microsoft.Network/privateEndpoints@2024-05-01' = {
  name: flexfunapp.name
  location: 'uksouth'
  properties: {
    subnet: {
      id: '/subscriptions/<subscriptionid>/resourceGroups/vivekchak-rg/providers/Microsoft.Network/virtualNetworks/vnetforflexfuncapp/subnets/InboundSubnet'
    }
    privateLinkServiceConnections: [
      {
        name: 'flexfunapp'
        properties: {
          privateLinkServiceId: flexfunapp.id
          groupIds: [
            'blob'
          ]
        }
      }
    ]
  }
}

I have followed all the given limitations and instructions given in this MS Doc but I'm unable to deploy the flex consumption plan function app.

Requested features are not supported in region. Please try another region. (Code:)

Here What I'm doing is:

  1. I'm trying to create the Azure Function App with Python 3.11 as Runtime stack in the flex consumption model of app service plan using BICEP template
  2. That function app with no public network access and integrated with outbound subnet and its private endpoint can be created using inbound subnet.

Solution

  • Please ensure that you follow this for the plan creation:

    resource flexFuncPlan 'Microsoft.Web/serverfarms@2024-04-01' = {
      name: planName
      location: location
      tags: tags
      kind: 'functionapp'
      sku: {
        tier: 'FlexConsumption'
        name: 'FC1'
      }
      properties: {
        reserved: true
      }
    }
    

    Here's a full example: https://github.com/Azure-Samples/azure-functions-flex-consumption-samples/blob/main/IaC/bicep/core/host/function.bicep