如何在使用Terraform创建Azure Function App时设置Java版本?

huangapple go评论130阅读模式
英文:

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

问题

在Azure门户中,我可以设置Java版本如下:
门户图片

在Terraform配置文件中,我只能使用以下方式设置Azure函数版本:

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
  }
}

在部署上述配置时,只有运行时设置为java,但由于版本未设置,我的部署无法正常工作。

在门户中的结果如下:
Java堆栈设置

英文:

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

答案1

得分: 1

我不知道为什么 Nancy Xiong 的答案被接受,因为它没有回答问题,问题明确是关于在 Terraform 中为 Azure 函数应用设置 Java 版本。这是正确的做法:

site_config {
    linux_fx_version = "JAVA|11"
}

site_config 文档

英文:

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

答案2

得分: 0

使用Azure提供程序版本>=v2.57.0,您可以通过site_config属性java_version设置Java版本。

java_version - (可选)由Azure函数应用托管的Java版本。可能的值为1.8、11。

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

  site_config {
    java_version = "11"
  }
}
英文:

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"
  }
}

答案3

得分: -1

你可以使用version参数来设置与函数应用关联的运行时版本。请参阅Argument Reference

此外,从文档中了解更多关于如何选择 Azure Functions 运行时版本的信息:How to target Azure Functions runtime versions

函数应用在特定版本的 Azure Functions 运行时上运行。有三个主要版本:1.x、2.x 和 3.x。默认情况下,函数应用在运行时的版本 3.x 中创建。

在这种情况下,您可以在resource "azurerm_function_app" "function-app"下添加参数version = "~3",这将获得您期望的结果。

英文:

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

如何在使用Terraform创建Azure Function App时设置Java版本?

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.

如何在使用Terraform创建Azure Function App时设置Java版本?

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

huangapple
  • 本文由 发表于 2020年8月13日 20:33:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/63395251.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定