首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在不删除资源组中现有Azure函数的情况下创建新的Azure函数应用程序

在不删除资源组中现有Azure函数的情况下创建新的Azure函数应用程序
EN

Stack Overflow用户
提问于 2020-01-23 21:17:38
回答 2查看 186关注 0票数 1

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

代码语言:javascript
复制
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
}
EN

回答 2

Stack Overflow用户

发布于 2020-01-24 12:04:00

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

票数 0
EN

Stack Overflow用户

发布于 2021-10-19 03:27:19

当你写的时候:

代码语言:javascript
复制
resource "azurerm_resource_group" "example" {

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

如果要保留现有资源组,但仍要引用其属性,请执行以下操作

代码语言:javascript
复制
data "azurerm_resource_group" "example"

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

代码语言:javascript
复制
azurerm_resource_group.example.location

将其替换为:

代码语言:javascript
复制
data.azurerm_resource_group.example.location
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59879519

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档