Skip to content

Commit

Permalink
Merge pull request #32 from keachi/data_lazy
Browse files Browse the repository at this point in the history
data lazy loading isn't a good idea.
  • Loading branch information
Arman-Keyoumarsi authored Jul 20, 2020
2 parents dac9c2c + 92bd720 commit 5dc846f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 5dc846f

Please sign in to comment.