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

disk sub resource of vsphere_virtual_machine #514

Closed
MattPumphrey opened this issue May 9, 2018 · 1 comment
Closed

disk sub resource of vsphere_virtual_machine #514

MattPumphrey opened this issue May 9, 2018 · 1 comment
Labels
enhancement Type: Enhancement

Comments

@MattPumphrey
Copy link

Hello all,

I am having some issues with using Disks in the VMware provider, Let

Terraform v0.11.2

  • provider.random v1.2.0
  • provider.vsphere v1.4.1

Affected Resource(s)

The issue that we are having seems to be the sub resource of disk { } within the vsphere_virtual_machine resource, my ultimate goal is to be able to dynamically add a secondary disk when needed, however this does not seem to be the case with using vsphere_datastore_cluster. I can add the second disk just fine, but I am unable to disable it.

I have tried several different methods. For example due to the way that the disk sub resource is setup I am currently at a loss as a way to dynamically associate disks to VMs without replicating a lot of code and recreating alot of modules. I see several paths forward, one would be to allow the attach feature to work on the cluster datastore, as well as to allow the vsphere_virtual_disk to be able use that same functionality. I have tested this with both vsphere_datastore_cluster and vsphere_datastore, and each one produces similar results. It would be great if the both types of datastores had the same features.

Terraform Configuration Files

data "vsphere_datastore_cluster" "datastore_cluster" {
  name          = "SRE Cluster"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

... snip ...
#As for other conditionals I tried were different ways of using the count option
### Second Disk###
resource "vsphere_virtual_disk" "datadisk" {
  vmdk_path  = "${var.vsphere_vm_name}-${format("%02d", count.index+1)}-data.vmdk"
  size       = "${var.data_disk_size >= 1 ? var.data_disk_size : 0}"

  datacenter = "/AUS2/" -> Had to define it here because it could not find ${data.vsphere_datacenter.dc.id}

  datastore  = "SRE_VMDK_1" -> had to define a datastore here because it could not use ${data.vsphere_datastore_cluster.datastore_cluster.id}

  type       = "thin"
}

####
resource "vsphere_virtual_machine" "vm" {
  name                 = "${var.vsphere_vm_name}-${element(random_id.unique_id.*.hex, count.index)}"
  resource_pool_id     = "${data.vsphere_resource_pool.pool.id}"
  datastore_cluster_id = "${data.vsphere_datastore_cluster.datastore_cluster.id}"

  num_cpus               = "${var.vsphere_vcpu_number}"
  memory                 = "${var.vsphere_memory_size}"
  guest_id               = "${lookup(var.guest_id,var.guest_id_ident)}"
  scsi_type              = "lsilogic"
  cpu_hot_add_enabled    = "true"
  cpu_hot_remove_enabled = "true"
  memory_hot_add_enabled = "true"
  cpu_share_level        = "normal"
  memory_share_level     = "normal"

  lifecycle {
    create_before_destroy = "true"
  }

  network_interface {
    network_id   = "${data.vsphere_network.network.id}"
    adapter_type = "e1000e"
  }

## Disk Based on Packer Template###
  disk {
    label       = "${var.vsphere_vm_name}-${format("%02d", count.index+1)}.vmdk"
    size        = "${data.vsphere_virtual_machine.template.disks.0.size}"
    unit_number = "0"
  }

##Secondary Disk##
  disk {
    label       = "${vsphere_virtual_disk.datadisk.vmdk_path}"
    size        = "${vsphere_virtual_disk.datadisk.size}"
    unit_number = "1"
  }

Expected Behavior

The Expected Behavior of all of these should have not to have added the disk

Actual Behavior

This is when I had a variable setup for data_volume_enable, similar to this post: issue #150

data.vsphere_datacenter.dc: Refreshing state...
data.vsphere_datastore_cluster.datastore_cluster: Refreshing state...
data.vsphere_resource_pool.pool: Refreshing state...
data.vsphere_virtual_machine.template: Refreshing state...
data.vsphere_network.network: Refreshing state...

------------------------------------------------------------------------

Error: Error running plan: 1 error(s) occurred:

* module.vmware-dev-1.vsphere_virtual_machine.vm: expected disk.1.size to be at least (1), got 0

Steps to Reproduce

These issues happen at both the plan and apply stages, it really just depends on how you try to limit the disk creation. It really just depends on how we are attaching the disk and what type of datastore we are using.

Important Factoids

We are working towards an immutable infrastructure with Terraform and Packer to help phase out Chef and a few other pieces of our environment. Currently we are running in an Enterprise Vsphere Cluster.

References

Are there any other GitHub issues (open or closed) or Pull Requests that should
be linked here? For example:
#401

@vancluever vancluever added the enhancement Type: Enhancement label May 10, 2018
@vancluever
Copy link
Contributor

Hey @MattPumphrey, thanks for the great description of your issue!

As discussed #401, this is something that ultimately can't be solved in the vSphere provider itself, and will have to wait until support for dynamic sub-resource blocks lands in TF core.

You can watch the issue referenced there (link) for updates on when this might be available for use in Terraform in any provider, including this one.

Thanks!

@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
enhancement Type: Enhancement
Projects
None yet
Development

No branches or pull requests

2 participants