0
votes

Trying to add 2 disks to a compute node for docker.. When I use the below stanza, the first 2 servers have the disks flipped.

resource "vsphere_virtual_machine" "compute" {
    # ...

    disk {
        template = "${var.cloud_template}"
        datastore = "${var.compute_datastore}"
      }

    disk {
      size = "${var.compute_datastore_var_size}"
      name = "${format("compute-var-disk-%s", element(var.compute_names,1))}"
      datastore = "${var.compute_datastore_var}"
    }

    disk {
      template = "${var.cloud_template}"
      datastore = "${var.compute_datastore}"
    }

    disk {
      size = "${var.compute_datastore_var_size2}"
      name = "${format("compute-var-disk2-%s", 
  element(var.compute_names,count.index))}"
      datastore = "${var.compute_datastore_var}"
    }
}

In Terraform plan and apply: servers 1&2 have disk 2 at 50gb and disk 3 at 25 (the opposite of what I need), while server 3&4 have them correct.

Any ideas that will help correct this?

1
I contemplated using the depends_on clause, but I don't know what or how to make the second disk dependent on the first diskScott Tee
Which resource type are you using here? Lots of different resource types have disk blocks and I suspect the answer here will depend on which one you're using...Martin Atkins
I've now noticed that the resources are listed in order with a numeric value, how is the value assigned? Example: disk.2151686800.size: "500" and disk.3070656849.size: "30"Scott Tee
Pardon my ignorance Martin, I'm not sure what your asking. Very new to terraform.Scott Tee
Just rebuild and computer 1 came out right, but 2, 3, 4 are all switched.. WTH.Scott Tee

1 Answers

0
votes

Unfortunately at this time there is an issue in how the vsphere_virtual_machine resource is defined in Terraform where the disk block is not set to be order-preserving, so the ordering of disks is undefined.

Until that issue is fixed, it's necessary to employ a workaround of looking up disks by their labels or some other available metadata, rather than relying on their attachment at particular indices.