【问题标题】:Terraform Azure function app from file upload来自文件上传的 Terraform Azure 函数应用
【发布时间】:2020-12-13 10:35:25
【问题描述】:

我正在尝试通过从本地文件系统上传一个 zip 文件来创建一个 java Azure 函数应用程序。下面是代码。从 Windows 10 系统运行时,它按预期工作。从 ubuntu 系统运行时,相同的代码似乎不起作用,没有错误,但函数应用在 azure 门户上没有任何功能。 Windows 和 ubuntu 上的 Terraform 版本相同(Terraform v0.12.28)。然而,它似乎不适用于 Ubuntu。以下是 azure 门户、函数应用上的错误消息 var.functionapp = "func_java.zip", zip 文件在 main.tf 的同一文件夹中

├── main.tf
├── tran_fun.zip
└── variables.tf


resource "azurerm_storage_blob" "appcode" {
    name = "functionapp.zip"
    storage_account_name = "${azurerm_storage_account.storage_account.name}"
    storage_container_name = "${azurerm_storage_container.storage_container_deployement.name}"
    type = "Block"
    source = "${var.functionapp}"
}


# // /***********************function app **********************************/
resource "azurerm_app_service_plan" "spp_service_plan" {
  name                = "${local.app_serv_plan_name}"
  resource_group_name = azurerm_resource_group.rg_creation.name
  location            = azurerm_resource_group.rg_creation.location
  kind                = "FunctionApp"

  sku {
    tier = "Dynamic"
    size = "Y1"
  }
}

resource "azurerm_function_app" "function_app" {
  name                      =  "${local.app_serv_name}" 
  resource_group_name = azurerm_resource_group.rg_creation.name
  location            = azurerm_resource_group.rg_creation.location
  app_service_plan_id       = azurerm_app_service_plan.spp_service_plan.id
  storage_connection_string = azurerm_storage_account.storage_account.primary_connection_string
  app_settings = {
    FUNCTIONS_WORKER_RUNTIME = "java"
    FUNCTIONS_EXTENSION_VERSION = "~3"
    APPINSIGHTS_INSTRUMENTATIONKEY = azurerm_application_insights.app_insights.instrumentation_key
    APPLICATIONINSIGHTS_CONNECTION_STRING = "InstrumentationKey=${azurerm_application_insights.app_insights.instrumentation_key}"
    HANA_CREDENTIALS = var.hanaCredentials
    TENANT_ID = var.cptenantId
    HASH = "${filebase64sha256("${var.functionapp}")}"
    WEBSITE_RUN_FROM_PACKAGE = "https://${azurerm_storage_account.storage_account.name}.blob.core.windows.net/${azurerm_storage_container.storage_container_deployement.name}/${azurerm_storage_blob.appcode.name}${data.azurerm_storage_account_sas.sas.sas}"
   
 }
}

以下是来自函数应用控制台的错误消息

【问题讨论】:

    标签: azure-functions terraform terraform-provider-azure


    【解决方案1】:

    如果.zip 文件与main.tf 位于同一文件夹中,您可以这样定义变量。

    variable "functionapp" {
        type = "string"
        default = "./func_java.zip"
    }
    

    它对我有用。

    更多详情,您可以阅读this blog

    【讨论】:

    • 感谢您的回复。我参考了同一个博客。从 Ubuntu 运行时它仍然无法正常工作, terraform apply 运行时没有错误。但是函数应用程序中没有函数。在 Azure 门户中,它显示错误:“mscorlib:could not find file D:\home\site\wwwroot\host.json”。奇怪的是,它在从 Windows 系统运行时运行良好。
    • 奇怪,我在 ubuntu 和 windows 中使用相同的代码没有任何问题。也许,func_java.zip 有问题?你怎么得到的?你能验证它吗?您是否添加了default = "./func_java.zip" 之类的路径,包括./
    • 导航到Azure门户---应用服务(你的函数应用)---控制台---运行ls命令,你能找到host.json文件,同时运行cat host.json检查内容。
    • 问题是使用terraform部署时,该路径D:\home\site\wwwroot上不存在host.json和其他功能应用文件。 tran_fun.zip 的文件是什么?改文件名func_java.zip
    • 感谢熊南希。这是 zip 文件的问题。当我将文件从 windows 移动到 linux 时文件损坏了。
    【解决方案2】:

    问题在于 zip 文件。从 Windows 移动时 Zip 文件损坏

    【讨论】:

      猜你喜欢
      • 2023-04-02
      • 2019-06-16
      • 2017-06-27
      • 2021-03-09
      • 2022-08-05
      • 2021-12-19
      • 2019-08-17
      • 1970-01-01
      • 2020-09-25
      相关资源
      最近更新 更多