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

Added new parameter for VM use_hot_add #136

Merged
merged 5 commits into from
Jun 5, 2020
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1
golang.org/x/sys v0.0.0-20190927073244-c990c680b611 // indirect
golang.org/x/tools v0.0.0-20200530233709-52effbd89c51 // indirect
)

go 1.13
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20200102140908-9497f49d5709/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e h1:3Dzrrxi54Io7Aoyb0PYLsI47K2TxkRQg+cqUn+m04do=
golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200530233709-52effbd89c51 h1:Wec8/IO8hAraBf0it7/dPQYOslIrgM938wZYNkLnOYc=
golang.org/x/tools v0.0.0-20200530233709-52effbd89c51/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
Expand Down
16 changes: 14 additions & 2 deletions nutanix/resource_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ func resourceNutanixVirtualMachine() *schema.Resource {

// RESOURCES ARGUMENTS

"use_hot_add": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"num_vnuma_nodes": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -917,6 +922,9 @@ func resourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{})
if err := d.Set("parent_reference", flattenReferenceValues(resp.Status.Resources.ParentReference)); err != nil {
return fmt.Errorf("error setting parent_reference for Virtual Machine %s: %s", d.Id(), err)
}
if err := d.Set("use_hot_add", d.Get("use_hot_add")); err != nil {
return fmt.Errorf("error setting use_hot_add for Virtual Machine %s: %s", d.Id(), err)
coderGo93 marked this conversation as resolved.
Show resolved Hide resolved
}

diskAddress := make(map[string]interface{})
mac := ""
Expand Down Expand Up @@ -1094,7 +1102,9 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{
o, n := d.GetChange("num_vcpus_per_socket")
res.NumVcpusPerSocket = utils.Int64Ptr(int64(n.(int)))
if n.(int) < o.(int) || n.(int) > o.(int) {
hotPlugChange = false
if !d.Get("use_hot_add").(bool) {
hotPlugChange = false
}
}
}
if d.HasChange("num_sockets") {
Expand All @@ -1108,7 +1118,9 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{
o, n := d.GetChange("memory_size_mib")
res.MemorySizeMib = utils.Int64Ptr(int64(n.(int)))
if n.(int) < o.(int) {
hotPlugChange = false
if !d.Get("use_hot_add").(bool) {
hotPlugChange = false
}
}
}
if d.HasChange("hardware_clock_timezone") {
Expand Down
97 changes: 97 additions & 0 deletions nutanix/resource_nutanix_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/spf13/cast"
)

func TestAccNutanixVirtualMachine_basic(t *testing.T) {
Expand Down Expand Up @@ -84,6 +85,58 @@ func TestAccNutanixVirtualMachine_WithDisk(t *testing.T) {
}})
}

func TestAccNutanixVirtualMachine_hotadd(t *testing.T) {
vmName := acctest.RandomWithPrefix("test-dou-vm")
cpus := 1
sockets := 1
memory := 1024
hotAdd := true
imageName := acctest.RandomWithPrefix("test-dou-image")

vmNameUpdated := acctest.RandomWithPrefix("test-dou-vm")
cpusUpdated := 2
socketsUpdated := 2
memoryUpdated := 2048
hotAddUpdated := false // To force a reboot
resourceName := "nutanix_virtual_machine.vm10"
imageNameUpdate := acctest.RandomWithPrefix("test-dou-image")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: testAccNutanixVMConfigHotAdd(vmName, cpus, sockets, memory, hotAdd, imageName),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixVirtualMachineExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "hardware_clock_timezone", "UTC"),
resource.TestCheckResourceAttr(resourceName, "power_state", "ON"),
resource.TestCheckResourceAttr(resourceName, "memory_size_mib", cast.ToString(memory)),
resource.TestCheckResourceAttr(resourceName, "num_sockets", cast.ToString(sockets)),
resource.TestCheckResourceAttr(resourceName, "num_vcpus_per_socket", cast.ToString(cpus)),
resource.TestCheckResourceAttr(resourceName, "use_hot_add", cast.ToString(hotAdd)),
),
},
{
Config: testAccNutanixVMConfigHotAdd(vmNameUpdated, cpusUpdated, socketsUpdated, memoryUpdated, hotAddUpdated, imageNameUpdate),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "hardware_clock_timezone", "UTC"),
resource.TestCheckResourceAttr(resourceName, "power_state", "ON"),
resource.TestCheckResourceAttr(resourceName, "memory_size_mib", cast.ToString(memoryUpdated)),
resource.TestCheckResourceAttr(resourceName, "num_sockets", cast.ToString(socketsUpdated)),
resource.TestCheckResourceAttr(resourceName, "num_vcpus_per_socket", cast.ToString(cpusUpdated)),
resource.TestCheckResourceAttr(resourceName, "use_hot_add", cast.ToString(hotAddUpdated))),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"disk_list"},
},
},
})
}

func TestAccNutanixVirtualMachine_updateFields(t *testing.T) {
r := acctest.RandInt()
resourceName := "nutanix_virtual_machine.vm2"
Expand Down Expand Up @@ -830,3 +883,47 @@ func testAccNutanixVMConfigCloningVM(r int) string {
}
`, r)
}

func testAccNutanixVMConfigHotAdd(vmName string, cpus, sockets, memory int, hotAdd bool, imageName string) 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 = "%[6]s"
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" "vm10" {
name = "%[1]s"
cluster_uuid = "${local.cluster1}"
num_vcpus_per_socket = %[2]d
num_sockets = %[3]d
memory_size_mib = %[4]d
power_state_mechanism = "ACPI"
use_hot_add = %[5]v
disk_list {
data_source_reference = {
kind = "image"
uuid = nutanix_image.cirros-034-disk.id
}
device_properties {
disk_address = {
device_index = 0
adapter_type = "SCSI"
}
device_type = "DISK"
}
}
}
`, vmName, cpus, sockets, memory, hotAdd, imageName)
}
1 change: 1 addition & 0 deletions website/docs/r/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The following arguments are supported:
* `power_state_mechanism`: - (Optional) Indicates the mechanism guiding the VM power state transition. Currently used for the transition to \"OFF\" state. Power state mechanism (ACPI/GUEST/HARD).
* `vga_console_enabled`: - (Optional) Indicates whether VGA console should be enabled or not.
* `disk_list` Disks attached to the VM.
* `use_hot_add`: - (Optional) Use Hot Add when modifying VM resources. Passing value false will result in VM reboots. Default value is `true`.

### Disk List

Expand Down