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

vsphere_virtual_disk does not support datastore clusters #638

Closed
brent-c-mills opened this issue Oct 10, 2018 · 7 comments
Closed

vsphere_virtual_disk does not support datastore clusters #638

brent-c-mills opened this issue Oct 10, 2018 · 7 comments
Labels
enhancement Type: Enhancement
Milestone

Comments

@brent-c-mills
Copy link

brent-c-mills commented Oct 10, 2018

Terraform Version

v0.11.8

vSphere Provider Version

v1.8.1

Affected Resource(s)

vsphere_virtual_disk
vsphere_virtual_machine

Terraform Configuration Files

resource "vsphere_virtual_disk" "secondary_disk" {
  count             = "${var.vsphere_vm_secondary_disk == "true" ? var.vsphere_vm_count : "0" }"
  size              = "${var.vsphere_vm_secondary_disk_size}"
  vmdk_path         = "${var.vsphere_vm_name}${count.index+var.vsphere_vm_name_padding+1}.${var.vsphere_vm_domain}_disk1.vmdk"
  datacenter        = "${var.vsphere_vm_datacenter}"
  datastore_cluster = "${var.vsphere_vm_datastore_cluster}"
  type              = "thin"
}
resource "vsphere_virtual_machine" "vm_2_disk" {
  count                = "${var.vsphere_vm_secondary_disk == "true" ? var.vsphere_vm_count : "0" }"
  name                 = "${var.vsphere_vm_name}${count.index+var.vsphere_vm_name_padding+1}.${var.vsphere_vm_domain}"
  resource_pool_id     = "${data.vsphere_resource_pool.resource_pool.id}"
  datastore_cluster_id = "${data.vsphere_datastore_cluster.datastore_cluster.id}"
  num_cpus             = "${var.vsphere_vm_cpu}"
  memory               = "${var.vsphere_vm_ram}"
  guest_id             = "${data.vsphere_virtual_machine.vm_template.guest_id}"
  scsi_type            = "${data.vsphere_virtual_machine.vm_template.scsi_type}"

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

  disk {
    label            = "disk0"
    size             = "${var.vsphere_vm_disk_0_size == "default" ? data.vsphere_virtual_machine.vm_template.disks.0.size : var.vsphere_vm_disk_0_size}"
    eagerly_scrub    = "${data.vsphere_virtual_machine.vm_template.disks.0.eagerly_scrub}"
    thin_provisioned = "${data.vsphere_virtual_machine.vm_template.disks.0.thin_provisioned}"
  }

  disk {
    label                = "disk1"
    unit_number          = "1"
    attach               = true
    datastore_cluster_id = "${data.vsphere_datastore_cluster.datastore_cluster.id}"
    path                 = "${var.vsphere_vm_name}${count.index+var.vsphere_vm_name_padding+1}.${var.vsphere_vm_domain}_disk1.vmdk"
  }

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

    customize {
      linux_options {
        host_name = "${var.vsphere_vm_name}${count.index+var.vsphere_vm_name_padding+1}"
        domain    = "${var.vsphere_vm_domain}"
      }

      network_interface {
        ipv4_address = "${device42_ip.vm_ip.*.ip[count.index]}"
        ipv4_netmask = "${var.vsphere_vm_cidr_mask}"
      }

      ipv4_gateway    = "${replace(var.vsphere_vm_subnet, var.vsphere_vm_gateway_search, var.vsphere_vm_gateway_replace)}"
      dns_server_list = ["${var.vsphere_vm_dns_servers}"]
      dns_suffix_list = ["${var.vsphere_vm_domain}"]
    }
  }

  lifecycle {
    ignore_changes = [
      "cluster",
      "disk",
      "datastore_id",
      "host_system_id",
      "resource_pool",
    ]
  }

  depends_on = ["device42_ip.vm_ip", "vsphere_virtual_disk.secondary_disk"]
}

Expected Behavior

the new virtual_disk should be created in the specified datastore_cluster (ideally on the same datastore as the virtual_machine to which is gets mounted)

Actual Behavior

Terraform fails complaining that datastore is required for vsphere_virtual_disk and that that datastore_cluster is not recognized. datastore_cluster_id fails on when using a datastore_cluster in the disk block of the vsphere_virtual_machine resource.

Error: module.vm-dc1.vsphere_virtual_disk.secondary_disk: "datastore": required field is not set

Error: module.vm-dc1.vsphere_virtual_disk.secondary_disk: : invalid or unknown key: datastore_cluster

Error: module.vm-dc1.vsphere_virtual_machine.vm_2_disk: "disk.1.attach": conflicts with datastore_cluster_id

Error: module.vm-dc1.vsphere_virtual_machine.vm_2_disk: "disk.1.path": conflicts with datastore_cluster_id

Error: module.vm-dc1.vsphere_virtual_machine.vm_2_disk: disk.1: invalid or unknown key: datastore_cluster_id

Steps to Reproduce

  1. terraform plan
@bill-rich bill-rich added the enhancement Type: Enhancement label Oct 11, 2018
@bcornils bcornils added this to the v2.0.0 milestone Feb 6, 2019
@amioranza
Copy link

+1

1 similar comment
@gugalnikov
Copy link

+1

@bill-rich
Copy link
Contributor

Hi @kaizoku0506!

Adding support for placing a vsphere_virtual_disk onto a datastore cluster using an SDRS recommendation would be possible, but (even through the vCenter client), the disk ends up being placed on a single datastore. Since it is not associated with another object, like a virtual machine, there isn't a way to find it later other than by the datastore and path. That is the reasoning for not supporting attach and datastore_cluster_id in the virtual machine disk sub resource.

Can I get some additional details on the use case this would cover? I'm trying to work out if there is already a solution in place that could help or what the best way to implement an enhancement would be.

If the goal is to create a disk that can be managed through SDRS and attached to a virtual machine, you can use a configuration like this:

resource "vsphere_virtual_machine" "vm_2_disk" {
...
  disk {
    label                = "disk1"
    unit_number          = "1"
    datastore_cluster_id = "${data.vsphere_datastore_cluster.datastore_cluster.id}"
     }
...

I suspect that doesn't cover the use case, but some extra help on describing it will hopefully get this moving along.

@bill-rich bill-rich added the waiting-response Status: Waiting on a Response label Apr 15, 2019
@amioranza
Copy link

Bill,

In my case I want to create new machines with any number of disks, using a counter for example without the need of multiple templates and some feature flags tricks.

I've tried to add this concept to a plan and the lack of attach option to disks created outside a virtual_machine resource I can't make my plan work.

Theres a option to create a machine with some kind of counter, like the virtual_machine have, but for disks?

My use case is for big data vm's that 4 disks of 250gb is better than a fat 1tb disk, I use terraform as a generic infrastructure builder using a pipeline and more generic and DRY better it is. I want to have very minimum number of modules to as much possibilities of reuse as I can. If I have the option to create as many disks I need for a vm, doesn't matter if it is using datasore or disek resoure or a disk counter inside the virtual_machine resource. Just having this option makes it much more generic and flexible.

Thanks.

@ghost ghost removed the waiting-response Status: Waiting on a Response label Apr 17, 2019
@pgrinstead1
Copy link

I am dealing with the same sort of issue. I need to be able to add disks using terraform and attach them. Similar to @amioranza I need to be able to tell terraform how many disks and the sizing of them.

I haven't been able to find a good explanation.

Thanks!

@bill-rich
Copy link
Contributor

Hi @amioranza & @pgrinstead1! The dynamic blocks that added in the Terraform 0.12 release should address the use case you are looking for. Now, you can include a dynamic "disk" block in your module and pass it a variable that will create the disks specified in the variable.

See the documentation on dynamic for more information, and the example below for how they can be utilized with the vsphere_virtual_machine resource to achieve your goal.

resource "vsphere_virtual_machine" "vm1" {
  name                       = "test"
  resource_pool_id           = data.vsphere_compute_cluster.cluster.resource_pool_id
  datastore_id               = var.test
  num_cpus                   = 1
  memory                     = 4096
  guest_id                   = data.vsphere_virtual_machine.template.guest_id
  host_system_id             = data.vsphere_host.hosts.id
  wait_for_guest_net_timeout = -1
  network_interface {
    network_id = data.vsphere_network.network.id
  }
  disk {
    unit_number      = 0
    label            = "disk0"
    thin_provisioned = true
    size             = data.vsphere_virtual_machine.template.disks[0].size
  }
  dynamic "disk" {
    iterator = d
    for_each = var.tv
    content {
      unit_number      = d.key
      label            = "disk${d.key}"
      thin_provisioned = true
      size             = d.value
    }
  }
}```

@hashicorp hashicorp locked and limited conversation to collaborators Apr 18, 2020
@ghost
Copy link

ghost commented Jun 2, 2021

This has been released in version 2.0.0 of the provider. To upgrade, change your provider block:

provider "vsphere" {
    version = "~> 2.0.0"
}
# ... other configuration ...

@hashicorp hashicorp unlocked this conversation Jun 2, 2021
@hashicorp hashicorp locked as resolved and limited conversation to collaborators Jun 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Type: Enhancement
Projects
None yet
Development

No branches or pull requests

6 participants