Search code examples
azureazure-bicepinfrastructure

Azure bicep templates to create fuction app giving the following error " LinuxFxVersion has an invalid value."


Am trying to use azure bicep templates to create a python function app however, getting the following error:

" LinuxFxVersion has an invalid value."

I used linuxFx version instead of python version as this is used in the following documentation:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-infrastructure-as-code?tabs=bicep#linux-1

Azure function bicep template

resource appService 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: appService
  location: location
  sku: {
    name: 'EP1'
    tier: 'ElasticPremium'
    family: 'EP'
  }
  kind: 'elastic'

}

var functionAppName = 'tml-functionapp'

resource functionApp 'Microsoft.Web/sites@2020-06-01' = {
  name: 'func-${project}-${role}-${env}'
  location: loc
  tags: appTagsComb
  kind: 'functionapp,linux'
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    reserved: true
    serverFarmId: appService.id
    siteConfig: {

      appSettings: [
        {
          name: 'AzureWebJobsStorage'
          value: 'DefaultEndpointsProtocol=https;AccountName=${funcApiStorage.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(funcApiStorage.id, funcApiStorage.apiVersion).keys[0].value}'
        }
        {
          name: 'FUNCTIONS_EXTENSION_VERSION'
          value: '~4'
        }
        {
          name: 'FUNCTIONS_WORKER_RUNTIME'
          value: 'python'
        }
        {
          name: 'WEBSITE_CONTENTSHARE'
          value: functionAppName
        }
        {
          name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
          value: 'DefaultEndpointsProtocol=https;AccountName=${funcApiStorage.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(funcApiStorage.id, funcApiStorage.apiVersion).keys[0].value}'

        }

        {
          name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
          value: funcappInsights.properties.InstrumentationKey
        }

      ]
      linuxFxVersion: 'Python|3.9'
      ftpsState: 'Disabled'
      minTlsVersion: '1.2'
    }
    httpsOnly: true

  }

Solution

  • You need to include the pythonVersion field also as shown :

    siteConfig: {
    pythonVersion: '3.9'
    linuxFxVersion: 'python|3.9'
    }
    

    After a workaround, I tried the below script to create a python function app as detailed in Github. I modified the script accordingly as per the requirements and was able to deploy successfully:

    param  name  string = 'jahnavistoragesceoo'
    param  location  string = 'EastUS'
    resource  storageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' = {
    name: name
    location: location
    sku: {
    name: 'Standard_LRS'
    }
    kind: 'StorageV2'
    }
    resource  applicationInsights  'Microsoft.Insights/components@2020-02-02' = {
    name: 'nameapplication-insights'
    location: location
    kind: 'web'
    properties: {
    Application_Type: 'web'
    Request_Source: 'rest'
    }
    }
    resource  hostingPlan  'Microsoft.Web/serverfarms@2021-03-01' = {
    name: name
    location: location
    kind: 'Linux'
    sku: {
    name: 'Y1'
    tier: 'Dynamic'
    }
    properties: {
    reserved: true
    }
    }
    resource  functionApp  'Microsoft.Web/sites@2021-03-01' = {
    name: name
    location: location
    kind: 'functionapp'
    identity: {
    type: 'SystemAssigned'
    }
    properties: {
    serverFarmId: hostingPlan.id
    siteConfig: {
    pythonVersion: '3.9'
    linuxFxVersion: 'python|3.9'
    appSettings: [
    {
    name: 'AzureWebJobsStorage'
    value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
    }
    {
    name: 'SCM_DO_BUILD_DURING_DEPLOYMENT' 
    value: 'true'
    }
    {
    name: 'ENABLE_ORYX_BUILD'  
    value: 'true'
    }
    {
    name: 'FUNCTIONS_EXTENSION_VERSION'
    value: '~4'
    }
    {
    name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
    value: applicationInsights.properties.InstrumentationKey
    }
    {
    name: 'FUNCTIONS_WORKER_RUNTIME'
    value: 'python'
    }
    ]
    }
    httpsOnly: true
    }
    }
    

    Output:

    enter image description here

    Deployment succeeded and created a python runtime stack function app in portal:

    enter image description here