Terraform deployed azure function not working with FUNCTIONS_WORKER_RUNTIME python setting

Viewed 37

Azure Function App displays "The service is unavailable." when FUNCTIONS_WORKER_RUNTIME = python app setting is set (with this setting commented the function displays "Your Functions 4.0 app is up and running").

As far as I understand, without this setting requirements.txt is not installed so the functions returns an error (from the logs: No module named 'azure.storage'...).

My terraform Azure Function code:

resource "azurerm_linux_function_app" "function_app" {
  name                = "${var.name}fa"
  resource_group_name = var.resource_group.name
  location            = var.resource_group.location

  storage_account_name       = var.storage_account.name
  storage_account_access_key = var.storage_account.primary_access_key
  service_plan_id            = var.service_plan.id

  site_config {
    application_insights_key               = azurerm_application_insights.ai.instrumentation_key
    application_insights_connection_string = azurerm_application_insights.ai.connection_string
  }

  app_settings = {
    APPINSIGHTS_INSTRUMENTATIONKEY = azurerm_application_insights.ai.instrumentation_key
    SCM_DO_BUILD_DURING_DEPLOYMENT = true
    FUNCTIONS_WORKER_RUNTIME       = "python"
  }
}
1 Answers

The correct configuration should look like this:

resource "azurerm_linux_function_app" "function_app" {
  name                = "${var.name}fa"
  resource_group_name = var.resource_group.name
  location            = var.resource_group.location

  storage_account_name       = var.storage_account.name
  storage_account_access_key = var.storage_account.primary_access_key
  service_plan_id            = var.service_plan.id

  site_config {
    application_insights_key               = azurerm_application_insights.ai.instrumentation_key
    application_insights_connection_string = azurerm_application_insights.ai.connection_string
    application_stack {
      python_version = "3.9"
    }
  }

  app_settings = {
    APPINSIGHTS_INSTRUMENTATIONKEY = azurerm_application_insights.ai.instrumentation_key
    SCM_DO_BUILD_DURING_DEPLOYMENT = true
  }
}
Related