【问题标题】:Create new Azure Function App without deleting existing Azure Functions in Resource Group在不删除资源组中现有 Azure Functions 的情况下创建新的 Azure Function App
【发布时间】:2020-05-09 18:45:55
【问题描述】:

我的资源组已经有一些函数应用。我现在想使用 Terraform 在同一个资源组中部署更多功能应用程序。问题是当我运行 Terraform 计划时,它告诉我以前的资源将被删除,新的资源将被创建。我想保留以前的资源。我在下面复制了我的代码。 Terraform 计划的结果是创建了 5 个资源,删除了 5 个资源。

variable "resource_group_name" {
  type = string
}

variable "location" {
  type = string
}

variable "resource_name" {
  type = string
}

resource "random_string" "random" {
  length = 9
  special = false
  number = true
  upper = false
}

variable "storage_account_tier" {
  type = string
  default = "Standard"
}

variable "storage_account_type" {
  type = string
  default = "LRS"
}

variable "service_plan_name" {
  type = string
}

variable "service_plan_tier" {
  type = string
  default = "Standard"
}

variable "service_plan_size" {
  type = string
  default = "S1"
}

resource "azurerm_resource_group" "example" {
  name     = var.resource_group_name
  location = var.location
}

resource "azurerm_storage_account" "example" {
  name                     = replace(join(",",["storageaccount",random_string.random.result]),",","")
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = var.storage_account_tier
  account_replication_type = var.storage_account_type
}

resource "azurerm_app_service_plan" "example" {
  name                = var.service_plan_name
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  sku {
    tier = var.service_plan_tier
    size = var.service_plan_size
  }
}

resource "azurerm_function_app" "example" {
  name                      = var.resource_name
  location                  = azurerm_resource_group.example.location
  resource_group_name       = azurerm_resource_group.example.name
  app_service_plan_id       = azurerm_app_service_plan.example.id
  storage_connection_string = azurerm_storage_account.example.primary_connection_string
}

【问题讨论】:

  • 计划是什么样的?您能否编辑您的问题以包含重现该问题的minimal reproducible example
  • 计划说创建了 5 个资源,删除了 5 个资源。很遗憾,我无法附上图片。
  • 复制并粘贴文本到您的问题中。不要将其作为图像。

标签: azure terraform azure-function-app


【解决方案1】:

我曾使用 Terraform 在 AWS 上创建基础设施,并使用 aws 资源解决了这个问题。如果您可以粘贴您的terraform plan 输出作为回复,我或许可以回答这个问题。

【讨论】:

    【解决方案2】:

    当你写作时:

    resource "azurerm_resource_group" "example" {
    

    您告诉 Terraform 您希望它完全管理该资源组。

    如果您想单独保留预先存在的资源组但仍引用其属性,请执行

    data "azurerm_resource_group" "example"
    

    然后而不是引用如下属性:

    azurerm_resource_group.example.location
    

    将其替换为:

    data.azurerm_resource_group.example.location
    

    【讨论】:

      猜你喜欢
      • 2022-07-24
      • 1970-01-01
      • 2020-12-23
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-01
      • 2019-01-10
      相关资源
      最近更新 更多