Skip to content

Commit

Permalink
Merge pull request #106 from yannickstruyf3/bugfix/fix-disk_address-a…
Browse files Browse the repository at this point in the history
…rray

bugfix device_properties in a disk_list
  • Loading branch information
marinsalinas authored Mar 25, 2020
2 parents fb21e01 + 3e2c308 commit dcfb2f5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nutanix/resource_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ func expandDiskList(d *schema.ResourceData, isCreation bool) ([]*v3.VMDisk, erro
if v1, ok := d["device_type"]; ok {
dp.DeviceType = utils.StringPtr(v1.(string))
}
if v2, ok := d["disk_address"]; ok {
if v2, ok := d["disk_address"]; ok && len(v2.(map[string]interface{})) > 0 {
da := v2.(map[string]interface{})
v3disk := &v3.DiskAddress{}
if di, diok := da["device_index"]; diok {
Expand Down
63 changes: 63 additions & 0 deletions nutanix/resource_nutanix_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,30 @@ func TestAccNutanixVirtualMachine_CloudInitCustomKeyValues(t *testing.T) {
})
}

func TestAccNutanixVirtualMachine_DeviceProperties(t *testing.T) {
r := acctest.RandInt()

resourceName := "nutanix_virtual_machine.vm9"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: testAccNutanixVMConfigWithDeviceProperties(r),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "disk_list.#"),
resource.TestCheckResourceAttr(resourceName, "disk_list.#", "1"),
),
},
{
ResourceName: "nutanix_virtual_machine.vm9",
ImportState: true,
ImportStateVerify: true,
},
}})
}

func testAccCheckNutanixVirtualMachineExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -696,3 +720,42 @@ resource "nutanix_virtual_machine" "vm8" {
}
`, r)
}

func testAccNutanixVMConfigWithDeviceProperties(r int) string {
return fmt.Sprintf(`
data "nutanix_clusters" "clusters" {}
locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}
resource "nutanix_image" "cirros-034-disk" {
name = "test-image-dou-vm-create-%[1]d"
source_uri = "http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img"
description = "heres a tiny linux image, not an iso, but a real disk!"
}
resource "nutanix_virtual_machine" "vm9" {
name = "test-dou-vm-%[1]d"
cluster_uuid = local.cluster1
num_vcpus_per_socket = 1
num_sockets = 1
memory_size_mib = 186
disk_list {
data_source_reference = {
kind = "image"
uuid = nutanix_image.cirros-034-disk.id
}
device_properties {
device_type = "DISK"
}
}
}
`, r)
}

0 comments on commit dcfb2f5

Please sign in to comment.