我正在尝试使用terraform部署azure功能,但我总是得到一个名为“无法下载ZIP FILE.txt”的文件,而不是实际部署的功能。
如果我粘贴从azure(从以前部署的存储帐户)中提取的实际SAS blob字符串,但terraform脚本失败,则它可以工作。zip文件似乎已正确部署到blob。
我把这个例子复制到了这里: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 curl:(22)请求的URL返回错误: 403服务器无法验证请求。确保Authorization header的值格式正确,包括签名。
有什么建议吗?我哪里做错了?
发布于 2019-07-05 22:05:25
我也遇到了同样的问题--你的WEBSITE_USE_ZIP value 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}中的值就是阻止函数app访问源代码压缩包的那个。如果您在控制台门户中生成访问URL,则可以正常工作。但是由于某种原因--我还没有弄清楚-- terraform模板生成的值由于签名字段格式错误而不能授予访问权限。
https://stackoverflow.com/questions/56355802
复制相似问题