如何使用 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 时抛出以下错误:

错误:不支持的块类型

第 78 行 terraformscript.tf,在资源 "azurerm_function_app" "testDeployTF" 中: 78: app_setting秒{

此处不需要类型为 "app_settings" 的块。

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

您可以查看有关azure-function-core-tool. And when you use the Azure CLI, it also needs to use the tool, see the steps in Create your first function from the command line的详细信息。

我在谷歌搜索地形错误时偶然发现了这个问题。您可以在 app_settings.

后简单地添加一个等号
app_settings = {
  Key = "Value"
}