在 terraform 中指定 azurerm_function_app 的操作系统是 linux

dag*_*da1 1 azure azure-cli terraform

我有以下azurerm_function_appterform 部分:

resource "azurerm_function_app" "main" {
  name                      = "${var.storage_function_name}"
  location                  = "${azurerm_resource_group.main.location}"
  resource_group_name       = "${azurerm_resource_group.main.name}"
  app_service_plan_id       = "${azurerm_app_service_plan.main.id}"
  storage_connection_string = "${azurerm_storage_account.main.primary_connection_string}"
  https_only                = true

  app_settings {
    "APPINSIGHTS_INSTRUMENTATIONKEY" = "${azurerm_application_insights.main.instrumentation_key}"
  }
}
Run Code Online (Sandbox Code Playgroud)

如何指定操作系统是linux?

Rah*_*kar 5

由于没有太多文档,我使用以下技术来构建 terraform 模板。

  1. 在 Azure 门户中创建所需的函数应用类型

    在此输入图像描述

  2. 使用 terraform import 命令导入相同的资源。

terraform导入azurerm_function_app.functionapp1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Web/sites/functionapp1

  1. 将检索以下信息

      id = /subscriptions/xxxx/resourceGroups/xxxxxx/providers/Microsoft.Web/sites/xxxx
      app_service_plan_id = /subscriptions/xxx/resourceGroups/xxxx/providers/Microsoft.Web/serverfarms/xxxx
      app_settings.% = 3
      app_settings.FUNCTIONS_WORKER_RUNTIME = node
      app_settings.MACHINEKEY_DecryptionKey = xxxxx
      app_settings.WEBSITE_NODE_DEFAULT_VERSION = 10.14.1
      client_affinity_enabled = false
      connection_string.# = 0
      default_hostname = xxxx.azurewebsites.net
      enable_builtin_logging = false
      enabled = true
      https_only = false
      identity.# = 0
      kind = functionapp,linux,container
      location = centralus
      name = xxxxx
      outbound_ip_addresses = xxxxxx
      resource_group_name = xxxx
      site_config.# = 1
      site_config.0.always_on = true
      site_config.0.linux_fx_version = DOCKER|microsoft/azure-functions-node8:2.0
      site_config.0.use_32_bit_worker_process = true
      site_config.0.websockets_enabled = false
      site_credential.# = 1
      site_credential.0.password =xxxxxx
      site_credential.0.username = xxxxxx
      storage_connection_string = xxxx
      tags.% = 0
      version = ~2
    
    Run Code Online (Sandbox Code Playgroud)
    1. 由此我构建了以下 terraform 模板
    provider "azurerm" {

    }

resource "azurerm_resource_group" "linuxnodefunction" {
    name     = "azure-func-linux-node-rg"
    location = "westus2"
}

resource "azurerm_storage_account" "linuxnodesa" {
    name                     = "azurefunclinuxnodesa"
    resource_group_name      = "${azurerm_resource_group.linuxnodefunction.name}"
    location                 = "${azurerm_resource_group.linuxnodefunction.location}"
    account_tier             = "Standard"
    account_replication_type = "LRS" 
}

resource "azurerm_app_service_plan" "linuxnodesp" {
    name                = "azure-func-linux-node-sp"
    location            = "${azurerm_resource_group.linuxnodefunction.location}"
    resource_group_name = "${azurerm_resource_group.linuxnodefunction.name}"
    kind                = "Linux"
    reserved            = true

    sku {
        capacity = 1
        size     = "P1v2"
        tier     = "PremiunV2"
    }
}

resource "azurerm_function_app" "linuxnodefuncapp" {
    name                      = "azure-func-linux-node-function-app"
    location                  = "${azurerm_resource_group.linuxnodefunction.location}"
    resource_group_name       = "${azurerm_resource_group.linuxnodefunction.name}"
    app_service_plan_id       = "${azurerm_app_service_plan.linuxnodesp.id}"
    storage_connection_string = "${azurerm_storage_account.linuxnodesa.primary_connection_string}"

    app_settings {
        FUNCTIONS_WORKER_RUNTIME     = "node"
        WEBSITE_NODE_DEFAULT_VERSION = "10.14.1"
    }

    site_config {
        always_on = true
        linux_fx_version = "DOCKER|microsoft/azure-functions-node8:2.0"
        use_32_bit_worker_process = true
        websockets_enabled = false            
    }
}
Run Code Online (Sandbox Code Playgroud)

让我们知道您的经验。我将尝试用这个测试一些东西。