terraform - terraform resource force creation
问题描述
I would like to know if there is a way to always create a new terraform resource and not destroy any previously deployed resource.
example resource group 1 deployment
provider "azurerm" {
version = "=2.20.0"
features {}
}
resource "azurerm_resource_group" "example" {
name = "rg-example-resources-1"
}
say now I want to deploy rg-example-resources-2 but I don't want to duplicate the resource block. I'm aware of count but I don't want to use it. if I change the resource group name terraform understand it as a replacement :(
any clue ?
解决方案
不知道你为什么需要这个,但你可以为此使用 terraform 工作区(当前工作区是'默认'):'terraform workspace new bar''terraform apply'
新资源将在新工作区中创建。要正确使用它,您需要更改资源组名称,例如:
resource "azurerm_resource_group" "example" {
name = "rg-example-resources-${terraform.workspace}"
}
在此处查看详细信息 - https://www.terraform.io/docs/state/workspaces.html
作为一个选项,您可以使用计数器块。如果您不想重新创建第一个资源组,可以使用 count 块生成相同的资源组:
resource "azurerm_resource_group" "example" {
name = "rg-example-resources-${count.index + 1}"
}
推荐阅读
- javascript - 如何本地化来自 html datetime-local 输入的输入
- javascript - 无法将特定类型作为参数分配给泛型
- java - Hibernate:查询未映射的类
- java - java - 如何将数据库项目显示为链接Java Spring?
- css - 纯 CSS 中的选框,不同的字符串长度但相同的速度
- node.js - Node Express 自定义 404 页面
- android - 所有可点击项目的涟漪效应都很慢
- javascript - 获取文本区域内当前光标位置下的文本
- python - 创建静态文件目录
- javascript - XMLHttpRequest() 返回 0