1
votes

I am trying to create a java Azure function app by uploading a zip file from the local file system . Below is the code. It is working as expected when ran from the windows 10 system. The same code doesn't seem to work when running from the ubuntu system, there was no error but the function app doesn't have any functions on azure portal. Terraform version is the same (Terraform v0.12.28) on both windows and ubuntu. Yet it doesn't seem to work on the Ubuntu. below is the error message on the azure portal, function app enter image description here var.functionapp = "func_java.zip", zip file is in the same folder of 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}"
   
 }
}

Below is the error message from the function app console enter image description here

2

2 Answers

1
votes

You could define the variable like this if the .zip file is in the same folder of main.tf.

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

It worked on my side.

enter image description here

For more details, you could read this blog.

0
votes

The issue was with zip file. Zip file got corrupted when moved from windows