azure - 创建新的 Azure Function App,而不删除资源组中现有的 Azure Functions

标签 azure terraform azure-function-app

我有一个资源组,其中已有一些函数应用。我现在想使用 Terraform 在同一资源组中部署更多功能应用程序。问题是当我运行 Terraform plan 时,它告诉我以前的资源将被删除,新的资源将被创建。我想保留以前的资源。我已经复制了下面的代码。 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
}

最佳答案

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

关于azure - 创建新的 Azure Function App,而不删除资源组中现有的 Azure Functions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59879519/

相关文章:

powershell - 如何使用Microsoft帐户添加-AzureRmAccount?

Azure 应用服务部署 - 服务主体帐户的最低角色

terraform - 使用 secretsmanager Terraform 设置 aws 访问 key 和 key

amazon-ec2 - 声明式云形成/Terraform 中的动态 EC2 资源配置

c# - HTTP按需触发azure函数多次调用自身

.net - 有没有一种方法可以从多个 .NET 项目创建一个 Azure Function App,并拥有所有这些项目的所有 Functions?

python - 如何从 Python 脚本中部署 Azure Function

c# - 应用程序抛出异常,web.config已被修改,但事实并非如此

node.js - Azure/Node.js 未发生异常 : Error: Cannot find module 'ms'

amazon-web-services - Terraform AWS Athena将Glue目录用作数据库