【问题标题】:how to deploy existing azure function using terraform如何使用 terraform 部署现有的 azure 功能
【发布时间】:2019-10-20 17:05:35
【问题描述】:

我在本地使用 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 放入 variable.tf 吗?
  • 我不认为你可以使用 terraform 一步创建包含代码的函数。
  • @CharlesXu 那你怎么办。基本上我有一个通过 Visual Studio 创建的天蓝色函数,我希望使用 terraform 将此函数部署到天蓝色门户
  • 当你使用visual studio时,它会使用azure-function-core-tool等扩展为你复制代码。而 terraform 正好可以为你创建功能。您需要自己将代码复制到函数中。
  • @CharlesXu 我希望这是自动化的,那么粘贴代码的最简单方法是什么?我在 blob 中上传了代码。

标签: azure azure-functions terraform terraform-provider-azure


【解决方案1】:

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

您可以查看有关azure-function-core-tool 的详细信息。而且在使用Azure CLI的时候,也需要用到工具,步骤见Create your first function from the command line

【讨论】:

    【解决方案2】:

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

    app_settings = {
      Key = "Value"
    }
    

    【讨论】:

      猜你喜欢
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-03
      • 2021-05-01
      • 2022-06-15
      • 2021-11-14
      相关资源
      最近更新 更多