azureterraformazure-functionsazure-functions-runtime

Terraform azurerm_linux_function_app doesn't support python version 3.10


I'm trying to deploy a python azure function to azure and I'm not able to do it with version 3.10, If I use version 3.9 it works. The weird thing is that Azure supports version 3.10, Terraform says it supports version 3.10. So what's the mistake?

ERROR

**Error: expected site_config.0.application_stack.0.python_version to be one of [3.9 3.8 3.7], got 3.10
│ 
│   with azurerm_linux_function_app.fn_analytics,
│   on python_analytics_functions.tf line 65, in resource "azurerm_linux_function_app" "fn_analytics": 
│   65:       python_version = "3.10"**

Scripts

resource "azurerm_service_plan" "asp_analytics" {
  name                = "<funct plan name>"
  location            = var.location
  resource_group_name = var.resource_group
  os_type             = "Linux"
  sku_name            = "Y1"
}

resource "azurerm_linux_function_app" "fn_analytics" {
  name                       = "<func name>"
  location                   = var.location
  resource_group_name        = var.resource_group
  storage_account_name       = azurerm_storage_account.safn.name
  storage_account_access_key = azurerm_storage_account.safn.primary_access_key
  service_plan_id            = azurerm_service_plan.asp_analytics.id

  identity {
    type         = "SystemAssigned"
  }

  app_settings = {
      ...
  }
  site_config {
    application_stack {
      python_version = "3.10"
    }
  }
}

Solution

  • It is a very transient issue which is related to the versions of terraform providers.

    Run terraform init -upgrade to avoid the version conflicts.

    Alternatively, you can use latest release of azurerm provider version by adding below block directly in your terraform code.

    terraform {
      required_providers {
        azurerm = {
          source = "hashicorp/azurerm"
          version = "3.96.0"
        }
      }
    }
    

    I have tried below code in my environment and was able to deploy it successfully as shown.

    Note: If you are running code in Azure CLI, check the version of it and upgrade it to the latest one using az upgrade command.

    terraform {
      required_providers {
        azurerm = {
          source = "hashicorp/azurerm"
          version = "3.96.0"
        }
      }
    }
    
    provider "azurerm" {
      features{}
    }
    data "azurerm_resource_group" "main"{
      name = "xxxx"
    }
    
    resource "azurerm_storage_account" "example" {
      name                     = "linuxfunctionappsa"
      resource_group_name      = azurerm_resource_group.example.name
      location                 = azurerm_resource_group.example.location
      account_tier             = "Standard"
      account_replication_type = "LRS"
    }
    
    resource "azurerm_service_plan" "asp_analytics" {
      name                = "myplanj"
      location            =  data.azurerm_resource_group.main.location
      resource_group_name = data.azurerm_resource_group.main.name
      os_type             = "Linux"
      sku_name            = "Y1"
    }
    
    resource "azurerm_linux_function_app" "fn_analytics" {
      name                       = "latestfuncj"
      location                   = data.azurerm_resource_group.main.location
      resource_group_name        = data.azurerm_resource_group.main.name
      storage_account_name       = azurerm_storage_account.example.name
      storage_account_access_key = azurerm_storage_account.example.primary_access_key
      service_plan_id            = azurerm_service_plan.asp_analytics.id
    
      identity {
        type         = "SystemAssigned"
      }
    
      app_settings = {
      }
      site_config {
        application_stack {
          python_version = "3.10"
        }
      }
    }
    

    Deployment succeeded:

    enter image description here

    enter image description here