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 Number is Changing on Second Apply #400

Closed
rbasore opened this issue Feb 14, 2018 · 5 comments
Closed

Disk Number is Changing on Second Apply #400

rbasore opened this issue Feb 14, 2018 · 5 comments
Labels
bug Type: Bug

Comments

@rbasore
Copy link

rbasore commented Feb 14, 2018

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform
issue trackers reserved for bug reports and feature requests. For general usage
questions, please see: https://www.terraform.io/community.html.

Terraform Version

Terraform v0.11.3

Run terraform -v to show the version. If you are not running the latest
version of Terraform, you can try upgrading, depending on if your problem is
with the provider or with Terraform core itself.

vSphere Provider Version

  • provider.vsphere v1.3.2

Affected Resource(s)

vsphere_virtual_machine

Terraform Configuration Files

data "vsphere_datacenter" "dc" {
  name = "${var.datacenter}" # Default PHX-IO
}

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

data "vsphere_resource_pool" "pool" {
  name          = "${var.resource_pool}"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_network" "network" {
  name          = "${var.network_name}"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_virtual_machine" "template" {
  name          = "${var.vm_template}"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "template_file" "init" {
  template = "${file("${path.module}/scripts/chef.tpl")}"

  vars {
    chefrepourl    = "${var.chefrepourl}"
    chefinstallurl = "${var.chefinstallurl}"
  }
}

data "template_file" "disk_config" {
  template = "${file("${path.module}/scripts/disk_config.tpl")}"
}

data "template_file" "disk_csv" {
  template = "${file("${path.module}/files/disk.tpl")}"
}

resource "vsphere_virtual_machine" "vm" {
  name                   = "${var.hostname}"
  resource_pool_id       = "${data.vsphere_resource_pool.pool.id}"
  datastore_id           = "${data.vsphere_datastore.datastore.id}"
  memory_hot_add_enabled = true
  cpu_hot_add_enabled    = true
  cpu_hot_remove_enabled = true

  num_cpus  = "${var.vm_vcpu}"                                     #Default is 4
  memory    = "${var.vm_mem}"                                      #Default is 16384
  guest_id  = "${data.vsphere_virtual_machine.template.guest_id}"  #optional but recommended
  scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}" #optional but recommended

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

  disk {
    label = "${var.hostname}"
    unit_number = 0
    size  = "${var.os_disk}"
  }

  disk {
    label       = "${var.hostname}_1"
    unit_number = 15
    size        = "${var.programs_disk_size}"
  }

  disk {
    label       = "${var.hostname}_2"
    unit_number = 16
    size        = "${var.data_disk_size}"
  }

  disk {
    label = "${var.hostname}_3"

    unit_number = 17
    size        = "${var.log_disk_size}"
  }

  disk {
    label = "${var.hostname}_4"

    unit_number = 18
    size        = "${var.systemdb_disk_size}"
  }

  disk {
    label = "${var.hostname}_5"

    unit_number = 19
    size        = "${var.tempdblog_disk_size}"
  }

  disk {
    label = "${var.hostname}_6"

    unit_number = 21
    size        = "${var.tempdb_disk_size}"
  }

  disk {
    label = "${var.hostname}_7"

    unit_number = 22
    size        = "${var.pagefile_disk_size}"
  }

# WINRM Stuff

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

## Clone stuff
      network_interface {
        ipv4_address    = "${var.ipv4_address}"
        ipv4_netmask    = "${var.ipv4_netmask}"
        dns_server_list = "${var.dns_server_list}"
        dns_domain      = "${var.domain}"
      }

      ipv4_gateway = "${var.ipv4_gateway}"
    }
  }
}

Expected Behavior

~ module.primary_sql_ndm.vsphere_virtual_machine.vm
disk.#: "8" => "8"

Actual Behavior

~ module.primary_sql_ndm.vsphere_virtual_machine.vm
disk.#: "1" => "8"

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform plan

Important Factoids

Code is cloning from a windows template that only has 1 drive. Not sure if this is the reason for the update

@vancluever vancluever added the bug Type: Bug label Feb 15, 2018
@vancluever
Copy link
Contributor

@rbasore your VM lacks the scsi_controller_count setting that would be needed to use a unit_number past 14 properly. Can you try changing your unit numbers so they are in the 0-14 range?

PS: It's best not to parameterize disk labels anymore. There's no reason to and it's possible it's just going to give you grief in the long run. The recommended convention is diskN, where N is your disk number. This will allow you to import VMs off of this configuration if you ever need to.

Adding this as a bug so that we can enforce the max unit number depending on scsi_controller_count.

@rismoney
Copy link

I can confirm I have this behavior as well and guessing its bug. I have had to work around this with ignore changes on disks altogether. I realized it as I was trying to implement the disk label and it was borked on the disk numbers being different. On single disk scenarios I have no issue so guessing it's just a mapping issue. (Disk Uuids?)

@rbasore
Copy link
Author

rbasore commented Feb 15, 2018

Thanks for replying. What is the format of using scsi_controller_count I am getting errors that state that this is not a valid option. I can not use 0-14 as I need them to be on a paravirtual adapter and scsi 0 is LSI logic. I can rebuild the whole template to make it paravirtual from the start but didn't want to have to do that.

@vancluever
Copy link
Contributor

@rbasore the documentation is here: https://www.terraform.io/docs/providers/vsphere/r/virtual_machine.html#scsi_controller_count

Unfortunately, for what you need to do, you will more than likely have to rebuild the template as you cannot mix SCSI controller types. The setting in scsi_type applies to all controllers and Windows does not necessarily like it when you change the type of the system disk.

@bill-rich
Copy link
Contributor

@rbasore @rismoney The disk number issue was a result of not checking if there were enough SCSI controllers to support the unit_number for the disks. If a template was used which had multiple controllers, the extras would not be removed, and disks would be created on those extra controllers even though the configuration was not aware of them. On the next run, there would be changes from the attempt to reconcile the unexpected disks.

#481 changes the disk sub-resource diff check behavior to run on all disks. Now disks with a unit_number set higher than scsi_controller_count supports will not be allowed.

@rbasore, this means that you will need to rebuild your template in order to keep additional disks on a paravirt controller since the configuration is being more strictly enforced. Sorry for the inconvenience on that, but this will help to reduce issues from unexpected configurations.

@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
bug Type: Bug
Projects
None yet
Development

No branches or pull requests

4 participants