通过文件上传 Terraform Azure 函数应用程序

Terraform Azure function app from file upload

我正在尝试通过从本地文件系统上传 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}"
   
 }
}

下面是函数应用控制台的错误信息

如果 .zip 文件与 main.tf.

在同一文件夹中,您可以这样定义变量
variable "functionapp" {
    type = "string"
    default = "./func_java.zip"
}

它对我有效。

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

问题出在 zip 文件上。从 windows

移动时 Zip 文件已损坏