How do you set the java version while creating Azure Function App using Terraform?

Viewed 1236

In the Azure Portal I can set the Java Version like follows: portal image

In the terraform config file I can only set the Azure Function version using:

resource "azurerm_function_app" "function-app" {
  name                       = "test"
  location                   = azurerm_resource_group.resource-group.location
  resource_group_name        = azurerm_resource_group.resource-group.name
  app_service_plan_id        = azurerm_app_service_plan.service-plan.id
  storage_account_name       = azurerm_storage_account.storage-account.name
  storage_account_access_key = azurerm_storage_account.storage-account.primary_access_key
  app_settings = {
    FUNCTION_APP_EDIT_MODE         = "readOnly"
    WEBSITE_RUN_FROM_PACKAGE       = 1
    FUNCTIONS_EXTENSION_VERSION    = 2
    FUNCTIONS_WORKER_RUNTIME       = "java"
    SCM_DO_BUILD_DURING_DEPLOYMENT = false
  }
}

When deploying the above configuration only the Runtime is set to java, but since the version is not set, my deployments are not working.

The result in portal looks as follows: java stack settings

3 Answers

I don't know how Nancy Xiong's answer was accepted, because it doesn't answer the question, which is specifically about setting the java version for azure function apps in terraform. This is how you do it correctly:

site_config {
       linux_fx_version = "JAVA|11"    
  }

site_config documentation

With the Azure Provider version >=v2.57.0, you can set the Java version via the site_config property java_version.

java_version - (Optional) Java version hosted by the function app in Azure. Possible values are 1.8, 11.

resource "azurerm_function_app" "function-app" {
  // ..

  site_config {
    java_version = "11"
  }
}

You could use version argument to set the runtime version associated with the Function App. See Argument Reference.

enter image description here

Also, from the docs---How to target Azure Functions runtime versions

A function app runs on a specific version of the Azure Functions runtime. There are three major versions: 1.x, 2.x, and 3.x. By default, function apps are created in version 3.x of the runtime.

enter image description here

In this case, you could add argument version = "~3" under the resource "azurerm_function_app" "function-app"". It will get your expected result.

Related