我正在使用 Terraform 在我们的 VMware vCenter 基础架构上部署一些开发和生产虚拟机,并使用 vsphere 标签来定义虚拟机的职责。因此,我在(子)模块中添加了以下内容:
resource "vsphere_tag" "tag" {
name = "SYS-Team"
category_id = "Responsibility"
description = "Systems group"
}
...
resource "vsphere_virtual_machine" "web" {
tags = [vsphere_tag.tag.id]
...
}
现在,当我销毁例如 dev 基础设施时,它还会删除 prod vsphere 标签,并让虚拟机没有标签。
我试图跳过生命周期的删除,但是我需要单独删除我不喜欢的每个资源。
lifecycle {
prevent_destroy = true
}
有没有办法在不让 Terraform 管理资源的情况下添加现有标签?没有将标签作为资源包含在内的硬编码,例如:
resource "vsphere_virtual_machine" "web" {
tags = [{
name = "SYS-Team"
category_id = "Responsibility"
description = "Systems group"
}
]
...
}