Skip to content

Commit f14d392

Browse files
committed
feat: added storage_config attribute in the data source, and created test case and doc
1 parent 58597b7 commit f14d392

3 files changed

Lines changed: 121 additions & 6 deletions

File tree

nutanix/data_source_nutanix_virtual_machine.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,43 @@ func dataSourceNutanixVirtualMachine() *schema.Resource {
522522
Type: schema.TypeInt,
523523
Computed: true,
524524
},
525+
"storage_config": {
526+
Type: schema.TypeList,
527+
Computed: true,
528+
MaxItems: 1,
529+
Elem: &schema.Resource{
530+
Schema: map[string]*schema.Schema{
531+
"flash_mode": {
532+
Type: schema.TypeString,
533+
Computed: true,
534+
},
535+
"storage_container_reference": {
536+
Type: schema.TypeList,
537+
Computed: true,
538+
Elem: &schema.Resource{
539+
Schema: map[string]*schema.Schema{
540+
"url": {
541+
Type: schema.TypeString,
542+
Computed: true,
543+
},
544+
"kind": {
545+
Type: schema.TypeString,
546+
Computed: true,
547+
},
548+
"name": {
549+
Type: schema.TypeString,
550+
Computed: true,
551+
},
552+
"uuid": {
553+
Type: schema.TypeString,
554+
Computed: true,
555+
},
556+
},
557+
},
558+
},
559+
},
560+
},
561+
},
525562
"device_properties": {
526563
Type: schema.TypeList,
527564
Computed: true,
@@ -570,7 +607,6 @@ func dataSourceNutanixVirtualMachine() *schema.Resource {
570607
},
571608
},
572609
},
573-
574610
"volume_group_reference": {
575611
Type: schema.TypeMap,
576612
Computed: true,
@@ -665,6 +701,9 @@ func dataSourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{
665701
if err := d.Set("parent_reference", flattenReferenceValues(resp.Status.Resources.ParentReference)); err != nil {
666702
return err
667703
}
704+
if err := d.Set("disk_list", flattenDiskList(resp.Status.Resources.DiskList)); err != nil {
705+
return err
706+
}
668707

669708
diskAddress := make(map[string]interface{})
670709
mac := ""
@@ -753,7 +792,7 @@ func dataSourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{
753792
d.Set("vga_console_enabled", utils.BoolValue(resp.Status.Resources.VgaConsoleEnabled))
754793
d.SetId(utils.StringValue(resp.Metadata.UUID))
755794

756-
return d.Set("disk_list", setDiskList(resp.Status.Resources.DiskList, resp.Status.Resources.GuestCustomization))
795+
return nil
757796
}
758797

759798
func resourceDatasourceVirtualMachineInstanceStateUpgradeV0(is map[string]interface{}, meta interface{}) (map[string]interface{}, error) {

nutanix/data_source_nutanix_virtual_machine_test.go

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,70 @@ func TestAccNutanixVirtualMachineDataSource_WithDisk(t *testing.T) {
4444
})
4545
}
4646

47+
func TestAccNutanixVirtualMachineDataSource_withDiskContainer(t *testing.T) {
48+
datasourceName := "data.nutanix_virtual_machine.nutanix_virtual_machine"
49+
vmName := acctest.RandomWithPrefix("test-dou-vm")
50+
51+
resource.Test(t, resource.TestCase{
52+
PreCheck: func() { testAccPreCheck(t) },
53+
Providers: testAccProviders,
54+
Steps: []resource.TestStep{
55+
{
56+
Config: testAccVMDataSourceWithDiskContainer(vmName),
57+
Check: resource.ComposeTestCheckFunc(
58+
resource.TestCheckResourceAttrSet(datasourceName, "vm_id"),
59+
resource.TestCheckResourceAttrSet(datasourceName, "disk_list.#"),
60+
resource.TestCheckResourceAttrSet(datasourceName, "disk_list.0.disk_size_bytes"),
61+
resource.TestCheckResourceAttrSet(datasourceName, "disk_list.0.disk_size_mib"),
62+
resource.TestCheckResourceAttrSet(datasourceName, "disk_list.0.storage_config.#"),
63+
resource.TestCheckResourceAttrSet(datasourceName, "disk_list.0.storage_config.0.storage_container_reference.#"),
64+
resource.TestCheckResourceAttrSet(datasourceName, "disk_list.0.storage_config.0.storage_container_reference.0.kind"),
65+
resource.TestCheckResourceAttrSet(datasourceName, "disk_list.0.storage_config.0.storage_container_reference.0.uuid"),
66+
resource.TestCheckResourceAttrSet(datasourceName, "disk_list.0.storage_config.0.storage_container_reference.0.name"),
67+
),
68+
},
69+
},
70+
})
71+
}
72+
73+
func testAccVMDataSourceWithDiskContainer(vmName string) string {
74+
return fmt.Sprintf(`
75+
data "nutanix_clusters" "clusters" {}
76+
77+
locals {
78+
cluster1 = [
79+
for cluster in data.nutanix_clusters.clusters.entities :
80+
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
81+
][0]
82+
}
83+
84+
resource "nutanix_virtual_machine" "vm-disk" {
85+
name = "%s"
86+
cluster_uuid = local.cluster1
87+
num_vcpus_per_socket = 1
88+
num_sockets = 1
89+
memory_size_mib = 186
90+
91+
disk_list {
92+
# disk_size_mib = 300
93+
disk_size_bytes = 68157440
94+
disk_size_mib = 65
95+
96+
storage_config {
97+
storage_container_reference {
98+
kind = "storage_container"
99+
uuid = "2bbe77bc-fd14-4697-8de1-6369757f9219"
100+
}
101+
}
102+
}
103+
}
104+
105+
data "nutanix_virtual_machine" "nutanix_virtual_machine" {
106+
vm_id = nutanix_virtual_machine.vm-disk.id
107+
}
108+
`, vmName)
109+
}
110+
47111
func testAccVMDataSourceConfig(r int) string {
48112
return fmt.Sprintf(`
49113
data "nutanix_clusters" "clusters" {}
@@ -72,25 +136,25 @@ data "nutanix_virtual_machine" "nutanix_virtual_machine" {
72136
func testAccVMDataSourceConfigWithDisk(r int) string {
73137
return fmt.Sprintf(`
74138
data "nutanix_clusters" "clusters" {}
75-
139+
76140
locals {
77141
cluster1 = "${data.nutanix_clusters.clusters.entities.0.service_list.0 == "PRISM_CENTRAL"
78142
? data.nutanix_clusters.clusters.entities.1.metadata.uuid : data.nutanix_clusters.clusters.entities.0.metadata.uuid}"
79143
}
80-
144+
81145
resource "nutanix_image" "cirros-034-disk" {
82146
name = "test-image-dou-vm-create-%[1]d"
83147
source_uri = "http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img"
84148
description = "heres a tiny linux image, not an iso, but a real disk!"
85149
}
86-
150+
87151
resource "nutanix_virtual_machine" "vm1" {
88152
name = "test-dou-vm-%[1]d"
89153
cluster_uuid = "${local.cluster1}"
90154
num_vcpus_per_socket = 1
91155
num_sockets = 1
92156
memory_size_mib = 186
93-
157+
94158
disk_list {
95159
data_source_reference = {
96160
kind = "image"

website/docs/d/virtual_machine.html.markdown

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ The device_properties attribute supports the following.
109109
* `device_type`: - A Disk type (default: DISK).
110110
* `disk_address`: - Address of disk to boot from.
111111

112+
### Storage Config
113+
User inputs of storage configuration parameters for VMs.
114+
115+
* `flash_mode`: - State of the storage policy to pin virtual disks to the hot tier. When specified as a VM attribute, the storage policy applies to all virtual disks of the VM unless overridden by the same attribute specified for a virtual disk.
116+
117+
* `storage_container_reference`: - Reference to a kind. Either one of (kind, uuid) or url needs to be specified.
118+
* `storage_container_reference.#.url`: - GET query on the URL will provide information on the source.
119+
* `storage_container_reference.#.kind`: - kind of the container reference
120+
* `storage_container_reference.#.name`: - name of the container reference
121+
* `storage_container_reference.#.uuid`: - uiid of the container reference
122+
123+
112124
### Sysprep
113125

114126
The guest_customization_sysprep attribute supports the following:

0 commit comments

Comments
 (0)