diff --git a/nutanix/resource_nutanix_virtual_machine.go b/nutanix/resource_nutanix_virtual_machine.go index 443f8d2a2..e039d4bec 100644 --- a/nutanix/resource_nutanix_virtual_machine.go +++ b/nutanix/resource_nutanix_virtual_machine.go @@ -1175,10 +1175,16 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{ if d.HasChange("disk_list") { preCdromCount, err := CountDiskListCdrom(res.DiskList) + if err != nil { + return err + } if res.DiskList, err = expandDiskList(d, false); err != nil { return err } postCdromCount, err := CountDiskListCdrom(res.DiskList) + if err != nil { + return err + } if preCdromCount != postCdromCount { hotPlugChange = false } diff --git a/nutanix/resource_nutanix_virtual_machine_test.go b/nutanix/resource_nutanix_virtual_machine_test.go index 8f1465ada..af90401d6 100644 --- a/nutanix/resource_nutanix_virtual_machine_test.go +++ b/nutanix/resource_nutanix_virtual_machine_test.go @@ -210,6 +210,37 @@ func TestAccNutanixVirtualMachine_PowerStateMechanism(t *testing.T) { }) } +func TestAccNutanixVirtualMachine_CdromGuestCustomisationReboot(t *testing.T) { + r := acctest.RandInt() + resourceName := "nutanix_virtual_machine.vm7" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckNutanixVirtualMachineDestroy, + Steps: []resource.TestStep{ + { + Config: testAccNutanixVMConfigCdromGuestCustomisationReboot(r), + Check: resource.ComposeTestCheckFunc( + testAccCheckNutanixVirtualMachineExists(resourceName), + ), + ExpectNonEmptyPlan: true, + }, + { + Config: testAccNutanixVMConfigCdromGuestCustomisationReboot(r), + Check: resource.ComposeTestCheckFunc( + testAccCheckNutanixVirtualMachineExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"disk_list"}, + }, + }, + }) +} + func testAccCheckNutanixVirtualMachineExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -579,3 +610,24 @@ resource "nutanix_virtual_machine" "vm6" { } `, r) } + +func testAccNutanixVMConfigCdromGuestCustomisationReboot(r int) string { + return fmt.Sprintf(` +data "nutanix_clusters" "clusters" {} + +locals { + cluster1 = "${data.nutanix_clusters.clusters.entities.0.service_list.0 == "PRISM_CENTRAL" + ? data.nutanix_clusters.clusters.entities.1.metadata.uuid : data.nutanix_clusters.clusters.entities.0.metadata.uuid}" +} + +resource "nutanix_virtual_machine" "vm7" { + name = "test-dou-%d" + cluster_uuid = "${local.cluster1}" + + num_vcpus_per_socket = 1 + num_sockets = 1 + memory_size_mib = 186 + guest_customization_cloud_init_user_data = base64encode("#cloud-config\nfqdn: test.domain.local") +} +`, r) +}