繁体   English   中英

如何使用 terraform 部署现有的 azure 函数

[英]how to deploy existing azure function using terraform

我有一个在本地使用 Visual Studio 创建的 azure 函数。 我正在尝试使用 terraform 部署 azure 函数,但它抛出错误

我正在尝试的代码如下所示:

resource "azurerm_function_app" "testDeployTF" {
  name                      = "testDeployADddecendant"
  location                  = "${azurerm_resource_group.rg-testDeployTF.location}"
  resource_group_name       = "${azurerm_resource_group.rg-testDeployTF.name}"
  app_service_plan_id       = "${azurerm_app_service_plan.sp-testDeployTF.id}"
  storage_connection_string = "DefaultEndpointsProtocol=https;AccountName=xxxx;AccountKey=xxxxxxxxxxx;EndpointSuffix=core.windows.net"

  app_settings {
    HASH            = "${base64sha256(file("FunctionApp1.zip"))}"
    WEBSITE_USE_ZIP = "https://${decendant.sa-testDeployTF.name}.blob.core.windows.net/${azurerm_storage_container.sc-testDeployTF.name}/${azurerm_storage_blob.sb-testDeployTF.name}${data.azurerm_storage_account_sas.sas-testDeployTF.sas}"

  }
}

如果我删除 app_setting 代码会创建一个新的空函数,但我想要的是我需要一个新函数,其中包含我在本地拥有的代码。

当我使用 app_seettings 时,上面的代码会引发以下错误:

错误:不支持的块类型

在 terraformscript.tf 第 78 行,在资源“azurerm_function_app”“testDeployTF”中:78:app_settings {

此处不需要“app_settings”类型的块。

对于您的问题,您可以使用 Terraform 创建一个空的 Azure 函数,不要使用您的代码。 此外,当您在本地使用 Visual Studio 时,它会为您创建空函数,然后使用 azure-function-core-tool 为您复制代码。

您可以查看有关azure-function-core-tool的详细信息。 并且在使用 Azure CLI 时,还需要使用该工具,请参阅从命令行创建您的第一个函数中的步骤。

我在谷歌搜索 terraform 错误时偶然发现了这个问题。 您可以简单地在app_settings后添加一个等号。

app_settings = {
  Key = "Value"
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM