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 name leads to error when cloning #320

Closed
nvideau opened this issue Dec 14, 2017 · 6 comments · Fixed by #329
Closed

computed name leads to error when cloning #320

nvideau opened this issue Dec 14, 2017 · 6 comments · Fixed by #329
Labels
bug Type: Bug

Comments

@nvideau
Copy link

nvideau commented Dec 14, 2017

Terraform Version

Terraform v0.11.1

vSphere Provider Version

provider.vsphere v1.1.0

Affected Resource(s)

vsphere_virtual_machine

Terraform Configuration Files

resource "random_id" "uuid" {
  byte_length = 2
  count= "${var.VM_count}"
}

data "vsphere_datacenter" "dc" {
  name = "${local.datacenter}"
}

data "vsphere_datastore" "datastore" {
  name          = "mydatastore"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_resource_pool" "pool" {
  name          = "${local.cluster}/Resources"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_network" "network" {
  name          = "${local.vlanLabel}"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_virtual_machine" "template" {
  name          = "${local.clusterName}_${
    local.datacenterName}_SRE_Channels_${var.VM_OSVersion}_${
   replace(random_shuffle.shuffle.result[count.index],"/\\D+/","")}"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

#VMs creations
resource "vsphere_virtual_machine" "VM" {
  name   = "${var.VM_pool}-${element(random_id.uuid.*.hex,var.VM_count)}"
  resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
  datastore_id     = "${data.vsphere_datastore.datastore.id}"
  folder = "${local.folder}"
  num_cpus = "${var.VM_vcpu}"
  memory = "${var.VM_memory}"

  guest_id = "${data.vsphere_virtual_machine.template.guest_id}"
  scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}"

  count = "${var.VM_count}"

  lifecycle {
    ignore_changes = [ "id","folder","name", "disk"]
  }

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

  disk {
    name = "${var.VM_pool}-${element(random_id.uuid.*.hex,var.VM_count)}.vmdk"
    size             = "${data.vsphere_virtual_machine.template.disks.0.size}"
    eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
    thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
  }

  disk {
    unit_number = 1
    name = "${var.VM_pool}_data.vmdk"
    size = "${var.VM_data_disk_size}"
  }

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

Expected Behavior

computed name bypassed

Actual Behavior

Error: Error refreshing state: 1 error(s) occurred:

2017/12/14 16:40:12 [ERROR] root: eval: *terraform.EvalDiff, err: disk.0: invalid disk name "" for cloning. Please rename this disk to ".vmdk"
2017/12/14 16:40:12 [ERROR] root: eval: *terraform.EvalSequence, err: disk.0: invalid disk name "" for cloning. Please rename this disk to ".vmdk"
2017/12/14 16:40:12 [TRACE] [walkRefresh] Exiting eval tree: vsphere_virtual_machine.VM
2017/12/14 16:40:12 [TRACE] dag/walk: upstream errored, not walking "provider.vsphere (close)"
2017/12/14 16:40:12 [TRACE] dag/walk: upstream errored, not walking "root"
2017/12/14 16:40:12 [DEBUG] plugin: waiting for all plugin processes to complete...

  • vsphere_virtual_machine.VM: 1 error(s) occurred:

  • vsphere_virtual_machine.VM: disk.0: invalid disk name "" for cloning. Please rename this disk to ".vmdk"

@nvideau
Copy link
Author

nvideau commented Dec 14, 2017

on version 0.4.2 I was using an uuid in the name of my cloned VMs and it worked well

@vancluever vancluever added question enhancement Type: Enhancement and removed question labels Dec 14, 2017
@vancluever
Copy link
Contributor

Hey @nvideau, this is a current limitation of how we are validating the disks, and is probably not something we will be fixing in this current minor version cycle. The reason is exactly as you mentioned it - there is a computed value there, but as we use the name field while processing the diff to track a disk's lifecycle, it's very important that it's available in its complete form at the time the disk is processed.

In 1.2.0 or 1.3.0 (time permitting) we plan on introducing a "label" field that will serve as an immutable key for a specific disk definition and deprecating name, at which point in time you can use that and not worry about assigning a name to a disk that has to match the virtual machine.

I'm moving this to "bug" not necessarily to fix this, but to make sure the extra validation is there to ensure that both VM and disk name cannot be a computed value for now. The name requirement should be able to be lifted after the the aforementioned changes are made.

Sorry for the inconvenience!

@vancluever vancluever added bug Type: Bug and removed enhancement Type: Enhancement labels Dec 14, 2017
@jason-azze
Copy link
Contributor

@vancluever Maybe I'm misunderstanding "make sure the extra validation is there to ensure that both VM and disk name cannot be a computed value for now", but if we can't use computed names for both (to make sure the disk name matches the VM name), how do we do it? I can't hard-code 1000 VM names. :-)

@vancluever
Copy link
Contributor

@jason-azze not all "computed" values are problematic - when I say computed, I mean the value must be known at plan-time. This generally means anything is okay in that field for interpolation except for the unknown output of a resource (ie: IDs generated from other resources, or in this case, the hex attribute of the random_id resource). Hope that helps!

@maxramqvist
Copy link

@vancluever this seems to destroy a lot of usage scenarios for this provider..? Like if we want to use computed hostnames for our vSphere machines. We just want to call them something like vsphere0-9999 or something like that. Do I misunderstand or do you have a nice way of supporting this? Thanks ;)

@rickardrosen
Copy link

To add to @maxramqvist comment; as per the process we create records in inventory/cmdb before creation of the actual VM.
We need to be able to set properties dynamically, or else the workflow breaks with regards to terraform workspaces and other integrations.

How do you propose we utilize this new provider for a module with terraform workspaces for example?

@ghost ghost locked and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Type: Bug
Projects
None yet
5 participants