diff --git a/main.tf b/main.tf index 3fbbd4d..ceb3a8a 100644 --- a/main.tf +++ b/main.tf @@ -45,14 +45,14 @@ data "vsphere_virtual_machine" "template" { data "vsphere_tag_category" "category" { count = var.tags != null ? length(var.tags) : 0 name = keys(var.tags)[count.index] - depends_on = [var.vm_depends_on] + depends_on = [var.tag_depends_on] } data "vsphere_tag" "tag" { count = var.tags != null ? length(var.tags) : 0 name = var.tags[keys(var.tags)[count.index]] category_id = "${data.vsphere_tag_category.category[count.index].id}" - depends_on = [var.vm_depends_on] + depends_on = [var.tag_depends_on] } locals { @@ -68,7 +68,7 @@ resource "vsphere_virtual_machine" "Linux" { resource_pool_id = data.vsphere_resource_pool.pool.id folder = var.vmfolder - tags = data.vsphere_tag.tag[*].id + tags = var.tag_ids != null ? var.tag_ids : data.vsphere_tag.tag[*].id custom_attributes = var.custom_attributes annotation = var.annotation extra_config = var.extra_config @@ -164,7 +164,7 @@ resource "vsphere_virtual_machine" "Windows" { resource_pool_id = data.vsphere_resource_pool.pool.id folder = var.vmfolder - tags = data.vsphere_tag.tag[*].id + tags = var.tag_ids != null ? var.tag_ids : data.vsphere_tag.tag[*].id custom_attributes = var.custom_attributes annotation = var.annotation extra_config = var.extra_config diff --git a/variables.tf b/variables.tf index cd83d07..6ded10f 100644 --- a/variables.tf +++ b/variables.tf @@ -90,11 +90,17 @@ variable "vmdns" { #Global Customization Variables variable "tags" { - description = "The names of any tags to attach to this resource. They shoud already exist" + description = "The names of any tags to attach to this resource. They must already exist." type = map default = null } +variable "tag_ids" { + description = "The ids of any tags to attach to this resource. They must already exist." + type = list + default = null +} + variable "custom_attributes" { description = "Map of custom attribute ids to attribute value strings to set for virtual machine." type = map @@ -352,3 +358,9 @@ variable "vm_depends_on" { type = any default = null } + +variable "tag_depends_on" { + description = "Add any external depend on module here like tag_depends_on = [vsphere_tag.foo.id]" + type = any + default = null +}