Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computed windows_sysprep_text failing validation #778

Closed
kvonbredow opened this issue May 31, 2019 · 0 comments · Fixed by #784
Closed

Computed windows_sysprep_text failing validation #778

kvonbredow opened this issue May 31, 2019 · 0 comments · Fixed by #784

Comments

@kvonbredow
Copy link

I am trying to create a vsphere_virtual_machine resource who's windows_sysprep_text relies on another resource which has not yet been created, and the customization block fails the validation step with the following message:

"one of windows_options or windows_sysprep_text must exist in VM customization options for Windows operating systems"

Looking at the code, it appears that the validation step does not accept computed values for the windows_sysprep_text field:

https://github.com/terraform-providers/terraform-provider-vsphere/blob/534931a5deb3be12c7217b6794781299fdce28cb/vsphere/internal/vmworkflow/virtual_machine_customize_subresource.go#L484-L496

The issue appears to originate from relying on the value from resourceDiff.Get() which throws away the information on whether the value is known or not at validation time, and could potentially be fixed by evaluating resourceDiff.NewValueKnown() in addition to checking for the empty string on line 488.

Terraform Version

Terraform v0.11.14
+ provider.template v2.1.2
+ provider.vsphere v1.11.0

vSphere Provider Version

1.11.0

Affected Resource(s)

Please list the resources as a list, for example:

  • vsphere_virtual_machine

Terraform Configuration Files

locals {
  n = "2"
}

resource "vsphere_folder" "folder" {
  count = "${local.n}"

  path          = "test-${count.index}"
  type          = "vm"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "template_file" "sysprep_xml" {
  count    = "${local.n}"
  template = "${file("sysprep.xml")}"

  vars = {
    foo = "${vsphere_folder.folder.*.id[count.index]}"
  }
}

resource "vsphere_virtual_machine" "test_sysprep_template" {
  count            = "${local.n}"
  name             = "test_sysprep_template_${count.index}"
  resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
  datastore_id     = "${data.vsphere_datastore.datastore.id}"
  folder           = "test"

  num_cpus            = "2"
  memory              = "4096"
  guest_id            = "${data.vsphere_virtual_machine.vm_template.guest_id}"
  enable_disk_uuid    = "true"
  sync_time_with_host = "true"

  scsi_type = "${data.vsphere_virtual_machine.vm_template.scsi_type}"

  network_interface {
    network_id   = "${data.vsphere_network.network.id}"
    adapter_type = "${data.vsphere_virtual_machine.vm_template.network_interface_types[0]}"
  }

  disk {
    label            = "disk0"
    size             = "32"
    eagerly_scrub    = "${data.vsphere_virtual_machine.vm_template.disks.0.eagerly_scrub}"
    thin_provisioned = "${data.vsphere_virtual_machine.vm_template.disks.0.thin_provisioned}"
  }

  clone {
    template_uuid = "${data.vsphere_virtual_machine.vm_template.id}"

    customize {
      windows_sysprep_text = "${data.template_file.sysprep_xml.*.rendered[count.index]}"
    }
  }
}

Expected Behavior

Creating a virtual machine which uses a computed value for windows_sysprep_text passes validation.

Actual Behavior

Creating a virtual machine which uses a computed value for windows_sysprep_text fails the validation check on the following line -
https://github.com/terraform-providers/terraform-provider-vsphere/blob/534931a5deb3be12c7217b6794781299fdce28cb/vsphere/internal/vmworkflow/virtual_machine_customize_subresource.go#L493

Steps to Reproduce

  1. terraform plan
@ghost ghost locked and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
1 participant