My Company has lots of VMs.
There are tags for these VMs, for example “Department Name”.
I now want to create a new VM with terraform and use existing tags, but when there is a new department it also needs to create a new tag.
For existing tags, I can use something like this:
data "vsphere_tag" "tag_department_name" {
name = var.department
category_id = "${data.vsphere_tag_category.category_department_name.id}"
}
If the tag does not exist I would need a the same block but as a resource:
resource "vsphere_tag" "tag_department_name" {
name = var.department
category_id = "${data.vsphere_tag_category.category_department_name.id}"
}
It should be possible to import existing tags, but when I use import inside a block I need the id and can not do it with just the name and category.
https://registry.terraform.io/providers/hashicorp/vsphere/latest/docs/resources/tag#importing
Is there a good way to handle such scenarios and what am I doing wrong?
lgruendh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.