我有一个资源组,它已经有一些功能应用程序。我现在想使用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
}发布于 2020-01-24 12:04:00
我曾使用Terraform在AWS上创建基础设施,并使用aws资源解决了此问题。如果您可以粘贴您的terraform plan输出作为答复,我也许能够回答这个问题。
发布于 2021-10-19 03:27:19
当你写的时候:
resource "azurerm_resource_group" "example" {您告诉Terraform,您希望它完全管理该资源组。
如果要保留现有资源组,但仍要引用其属性,请执行以下操作
data "azurerm_resource_group" "example"然后,不是引用如下属性:
azurerm_resource_group.example.location将其替换为:
data.azurerm_resource_group.example.locationhttps://stackoverflow.com/questions/59879519
复制相似问题