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

bugfix device_properties in a disk_list #106

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}