Terraform部署azure功能导致“无法下载ZIP FILE.txt”

时间:2019-05-29 08:06:05

标签: azure-functions terraform

我正在尝试使用terraform部署Azure函数,但我一直只得到一个名为“ FAILED TO DOWNLOAD ZIP FILE.txt”的文件,而不是实际部署的函数。

如果我粘贴从azure(从先前部署的存储帐户)提取的实际SAS blob字符串,则该方法有效,但是terraform脚本失败。 zip文件似乎已正确部署到blob。

我几乎在此处复制粘贴了theis示例:http://vgaltes.com/post/deploying-azure-functions-using-terraform/

我是terraform的新手,所以这里可能缺少一些明显的即时消息...

 resource "azurerm_resource_group" "rg" {
 name = "myName"
 location = "northEurope"
}

resource "random_string" "storage_name" {
 length = 16
 special = false
 upper = false
}
resource "random_string" "function_name" {
 length = 16
 special = false
 upper = false
}
resource "random_string" "app_service_plan_name" {
 length = 16
 special = false
}

resource "azurerm_storage_account" "storage" {
 name = "${random_string.storage_name.result}"
 resource_group_name = "${azurerm_resource_group.rg.name}"
 location = "${azurerm_resource_group.rg.location}"
 account_tier = "Standard"
 account_replication_type = "LRS"
}
resource "azurerm_storage_container" "storage_container" {
 name = "func"
 resource_group_name = "${azurerm_resource_group.rg.name}"
 storage_account_name = "${azurerm_storage_account.storage.name}"
 container_access_type = "blob"
}

resource "azurerm_storage_blob" "storage_blob" {
 name = "HelloWorld.zip"
 resource_group_name = "${azurerm_resource_group.rg.name}"
 storage_account_name = "${azurerm_storage_account.storage.name}"
 storage_container_name = "${azurerm_storage_container.storage_container.name}"
 type = "block"
 source = "./../FunctionAppZip/HelloWorld.zip"
}
data "azurerm_storage_account_sas" "storage_sas" {
 connection_string = "${azurerm_storage_account.storage.primary_connection_string}"
 https_only = false
resource_types {
 service = false
 container = false
 object = true
 }
services {
 blob = true
 queue = true
 table = true
 file = true
 }
start = "2019–05–21"
 expiry = "2029–05–21"
permissions {
 read = true
 write = true
 delete = true
 list = true
 add = true
 create = true
 update = true
 process = true
 }
}

resource "azurerm_app_service_plan" "plan" {
 name = "${random_string.app_service_plan_name.result}"
 location = "${azurerm_resource_group.rg.location}"
 resource_group_name = "${azurerm_resource_group.rg.name}"
 kind = "functionapp"
sku {
 tier = "Dynamic"
 size = "Y1"
 }
}

resource "azurerm_function_app" "function" {
  name = "${random_string.storage_name.result}"
  location = "${azurerm_resource_group.rg.location}"
  resource_group_name = "${azurerm_resource_group.rg.name}"
  app_service_plan_id = "${azurerm_app_service_plan.plan.id}"
  storage_connection_string = "${azurerm_storage_account.storage.primary_connection_string}"
  app_settings {
    FUNCTIONS_WORKER_RUNTIME = "dotnet"
    FUNCTION_APP_EDIT_MODE = "readwrite"
    https_only = false
    HASH = "${base64sha256(file("./../FunctionAppZip/HelloWorld.zip"))}"
    WEBSITE_RUN_FROM_PACKAGE = 1    
    WEBSITE_USE_ZIP = "https://${azurerm_storage_account.storage.name}.blob.core.windows.net/${azurerm_storage_container.storage_container.name}/${azurerm_storage_blob.storage_blob.name}${data.azurerm_storage_account_sas.storage_sas.sas}"
  }
}

当我下载azure函数内容时,它只是一个名为“ FAILED TO DOWNLOAD ZIP FILE.txt”的文件。

包含以下内容:

%总接收百分比%Xferd平均速度时间时间时间当前                                  Dload上传总花费左手速度

0 0 0 0 0 0 0 0-:-:--:-:--:-:-0   0 0 0 0 0 0 0 0-:-:--:-:--:-:-0 curl:(22)请求的URL返回错误:403服务器无法验证请求。请确保正确构成Authorization标头的值(包括签名)。

有人建议我做错了什么吗?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题-您的WEBSITE_USE_ZIPhttps://${azurerm_storage_account.storage.name}.blob.core.windows.net/${azurerm_storage_container.storage_container.name}/${azurerm_storage_blob.storage_blob.name}${data.azurerm_storage_account_sas.storage_sas.sas}中的值使函数应用无法访问源代码的zip包。如果您在控制台门户网站内生成访问URL,则它可以工作。但是由于某些原因-我还没有解决-terraform模板生成的值由于签名字段格式错误而无法授予访问权限。