hashicorp / terraform-provider-vsphere

Terraform Provider for VMware vSphere
https://registry.terraform.io/providers/hashicorp/vsphere/
Mozilla Public License 2.0
618 stars 452 forks source link

Terraform apply wants to change disk.0.disk_sharing every time. #290

Closed hmalinov closed 5 years ago

hmalinov commented 6 years ago

Terraform Version

Terraform v0.11.1

vSphere Provider Version

provider.vsphere ~> 1.1.0

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

# main.tf

data "vsphere_datacenter" "dc" {
  name = "colo.elex.be"
}

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

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

data "vsphere_virtual_machine" "template" {
  name          = "centos74_packer.v1"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

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

# vm configuration
resource "vsphere_virtual_machine" "osnode1-test_colo_elex_be" {
  datastore_id          = "${data.vsphere_datastore.ds1test.id}"
  resource_pool_id      = "${data.vsphere_resource_pool.pool.id}"
  guest_id              = "${data.vsphere_virtual_machine.template.guest_id}"
  scsi_type             = "${data.vsphere_virtual_machine.template.scsi_type}"

  name          = "osnode1-test.colo.elex.be"
  num_cpus      = 2
  memory        = 4096

  cpu_hot_add_enabled           = true
  cpu_hot_remove_enabled        = true
  memory_hot_add_enabled        = true
  enable_logging                = true

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

  disk { 
    name = "osnode1-test.colo.elex.be.vmdk"
    size = "${data.vsphere_virtual_machine.template.disks.0.size}"
    thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
  }

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

    customize {
      linux_options {
        host_name = "osnode1-test"
        domain    = "colo.elex.be"
      }

      network_interface {
        ipv4_address    = "10.32.243.31"
        ipv4_netmask    = 20
      }

      ipv4_gateway      = "10.32.240.100"
      dns_server_list   = ["10.32.240.136"]
      dns_suffix_list   = ["colo.elex.be"]
    }
  }
} 

Expected Behavior

  disk.0.disk_sharing: "" => "sharingNone"
module.vms.vsphere_virtual_machine.osnode1-test_colo_elex_be: Modifying... (ID: 4216750d-601f-4401-3e57-0c7f57c851e5)
  disk.0.disk_sharing: "" => "sharingNone"
module.vms.vsphere_virtual_machine.hmasai-test_colo_elex_be: Still modifying... (ID: 42168a63-d67b-f103-a4cb-8a6e4d4e025c, 10s elapsed)
module.vms.vsphere_virtual_machine.osnode1-test_colo_elex_be: Still modifying... (ID: 4216750d-601f-4401-3e57-0c7f57c851e5, 10s elapsed)
module.vms.vsphere_virtual_machine.hmasai-test_colo_elex_be: Still modifying... (ID: 42168a63-d67b-f103-a4cb-8a6e4d4e025c, 20s elapsed)
module.vms.vsphere_virtual_machine.osnode1-test_colo_elex_be: Still modifying... (ID: 4216750d-601f-4401-3e57-0c7f57c851e5, 20s elapsed)
module.vms.vsphere_virtual_machine.osnode1-test_colo_elex_be: Still modifying... (ID: 4216750d-601f-4401-3e57-0c7f57c851e5, 30s elapsed)
module.vms.vsphere_virtual_machine.hmasai-test_colo_elex_be: Still modifying... (ID: 42168a63-d67b-f103-a4cb-8a6e4d4e025c, 30s elapsed)
module.vms.vsphere_virtual_machine.osnode1-test_colo_elex_be: Still modifying... (ID: 4216750d-601f-4401-3e57-0c7f57c851e5, 40s elapsed)
module.vms.vsphere_virtual_machine.hmasai-test_colo_elex_be: Still modifying... (ID: 42168a63-d67b-f103-a4cb-8a6e4d4e025c, 40s elapsed)
module.vms.vsphere_virtual_machine.osnode1-test_colo_elex_be: Still modifying... (ID: 4216750d-601f-4401-3e57-0c7f57c851e5, 50s elapsed)
module.vms.vsphere_virtual_machine.hmasai-test_colo_elex_be: Still modifying... (ID: 42168a63-d67b-f103-a4cb-8a6e4d4e025c, 50s elapsed)
module.vms.vsphere_virtual_machine.osnode1-test_colo_elex_be: Still modifying... (ID: 4216750d-601f-4401-3e57-0c7f57c851e5, 1m0s elapsed)
module.vms.vsphere_virtual_machine.hmasai-test_colo_elex_be: Still modifying... (ID: 42168a63-d67b-f103-a4cb-8a6e4d4e025c, 1m0s elapsed)
module.vms.vsphere_virtual_machine.hmasai-test_colo_elex_be: Modifications complete after 1m2s (ID: 42168a63-d67b-f103-a4cb-8a6e4d4e025c)
module.vms.vsphere_virtual_machine.osnode1-test_colo_elex_be: Modifications complete after 1m5s (ID: 4216750d-601f-4401-3e57-0c7f57c851e5)

Apply complete! Resources: 0 added, 2 changed, 0 destroyed.

Should have changed the disk.0.disk_sharing

Actual Behavior

Again wants to change the disk.0.disk_sharing on next ./terraform plan

$ ./terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

data.vsphere_datacenter.dc: Refreshing state...
data.vsphere_network.network: Refreshing state...
data.vsphere_resource_pool.pool: Refreshing state...
data.vsphere_datastore.ds1test: Refreshing state...
data.vsphere_virtual_machine.template: Refreshing state...
vsphere_virtual_machine.hmasai-test_colo_elex_be: Refreshing state... (ID: 42168a63-d67b-f103-a4cb-8a6e4d4e025c)
vsphere_virtual_machine.osnode1-test_colo_elex_be: Refreshing state... (ID: 4216750d-601f-4401-3e57-0c7f57c851e5)

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

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  ~ module.vms.vsphere_virtual_machine.hmasai-test_colo_elex_be
      disk.0.disk_sharing: "" => "sharingNone"

  ~ module.vms.vsphere_virtual_machine.osnode1-test_colo_elex_be
      disk.0.disk_sharing: "" => "sharingNone"

Plan: 0 to add, 2 to change, 0 to destroy.

Steps to Reproduce

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

  1. terraform apply
  2. terraform apply

Important Factoids

Seems that it does not work on ESXi hosts with verison 5.5. It works fin on ESXi hosts 6.0 .

Apparently disk sharing is available since 6.0 - http://pubs.vmware.com/vsphere-6-5/index.jsp#com.vmware.wssdk.smssdk.doc/vim.vm.device.VirtualDisk.Sharing.html

References

GH-265

kennylindholm commented 6 years ago

This also happens on v1.1.1

hmalinov commented 6 years ago

First of all thank you for the awesome work guys.

Regarding the bug, it is pretty nasty one, which makes Terraform unusable in a mixed environment with 5.5 and 6.0 version of vsphere. Every time I want to do something results in >20 virtual machines restarted.

Is there a possible workaround ? Do you have an estimate when can it be solve?

Thank you once again.

jnahelou commented 6 years ago

My workaround :

lifecycle {
    ignore_changes = ["disk.0.disk_sharing", "disk.1.disk_sharing", "disk.2.disk_sharing"]                                                                                                       
  }

I hardcoded the list due to unsupported index wildcard :

* vsphere_virtual_machine.vm: ignore_changes does not support using a partial string together with a wildcard: disk.*.disk_sharing

ignore_changes = ["disk"] is too much generic, I don't want to ignore others properties.. Seems like same use case as https://github.com/hashicorp/terraform/issues/5666

hmalinov commented 6 years ago

@jnahelou Thank you, it is working perfectly .

bill-rich commented 5 years ago

This should be resolved now that disk sharing is supported. Please reopen the issue if you're still experiencing this.