Skip to content

Commit 0f84220

Browse files
setting machine type in update context (#630)
1 parent 033e0f7 commit 0f84220

2 files changed

Lines changed: 156 additions & 0 deletions

File tree

nutanix/resource_nutanix_virtual_machine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,7 @@ func preFillResUpdateRequest(res *v3.VMResources, response *v3.VMIntentResponse)
18761876
res.VgaConsoleEnabled = response.Spec.Resources.VgaConsoleEnabled
18771877
res.HardwareClockTimezone = response.Spec.Resources.HardwareClockTimezone
18781878
res.DiskList = response.Spec.Resources.DiskList
1879+
res.MachineType = response.Spec.Resources.MachineType
18791880

18801881
nold := make([]*v3.VMNic, len(response.Spec.Resources.NicList))
18811882

nutanix/resource_nutanix_virtual_machine_test.go

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package nutanix
33
import (
44
"fmt"
55
"os"
6+
"regexp"
67
"strings"
78
"testing"
89
"time"
@@ -563,6 +564,78 @@ func TestAccNutanixVirtualMachine_SysprepCustomKeyValues(t *testing.T) {
563564
})
564565
}
565566

567+
func TestAccNutanixVirtualMachine_SecureBoot(t *testing.T) {
568+
r := acctest.RandInt()
569+
resourceName := "nutanix_virtual_machine.test"
570+
name := fmt.Sprintf("test-vm-%d", r)
571+
desc := "this is vm desc"
572+
updatedName := fmt.Sprintf("test-vm-%d-updated", r)
573+
updatedDesc := "this is updated desc"
574+
memory := "200"
575+
updatedMem := "300"
576+
resource.Test(t, resource.TestCase{
577+
PreCheck: func() { testAccPreCheck(t) },
578+
Providers: testAccProviders,
579+
CheckDestroy: testAccCheckNutanixVirtualMachineDestroy,
580+
Steps: []resource.TestStep{
581+
{
582+
Config: testAccNutanixVMConfigWithSecureBoot(name, desc, memory),
583+
Check: resource.ComposeTestCheckFunc(
584+
testAccCheckNutanixVirtualMachineExists(resourceName),
585+
resource.TestCheckResourceAttr(resourceName, "name", name),
586+
resource.TestCheckResourceAttr(resourceName, "description", desc),
587+
resource.TestCheckResourceAttr(resourceName, "hardware_clock_timezone", "UTC"),
588+
resource.TestCheckResourceAttr(resourceName, "power_state", "ON"),
589+
resource.TestCheckResourceAttr(resourceName, "memory_size_mib", memory),
590+
resource.TestCheckResourceAttr(resourceName, "num_sockets", "1"),
591+
resource.TestCheckResourceAttr(resourceName, "num_vcpus_per_socket", "3"),
592+
resource.TestCheckResourceAttr(resourceName, "machine_type", "Q35"),
593+
resource.TestCheckResourceAttr(resourceName, "boot_type", "SECURE_BOOT"),
594+
),
595+
},
596+
{
597+
Config: testAccNutanixVMConfigWithSecureBoot(updatedName, updatedDesc, updatedMem),
598+
Check: resource.ComposeTestCheckFunc(
599+
testAccCheckNutanixVirtualMachineExists(resourceName),
600+
resource.TestCheckResourceAttr(resourceName, "name", updatedName),
601+
resource.TestCheckResourceAttr(resourceName, "description", updatedDesc),
602+
resource.TestCheckResourceAttr(resourceName, "hardware_clock_timezone", "UTC"),
603+
resource.TestCheckResourceAttr(resourceName, "power_state", "ON"),
604+
resource.TestCheckResourceAttr(resourceName, "memory_size_mib", updatedMem),
605+
resource.TestCheckResourceAttr(resourceName, "num_sockets", "1"),
606+
resource.TestCheckResourceAttr(resourceName, "num_vcpus_per_socket", "3"),
607+
resource.TestCheckResourceAttr(resourceName, "machine_type", "Q35"),
608+
resource.TestCheckResourceAttr(resourceName, "boot_type", "SECURE_BOOT"),
609+
),
610+
},
611+
{
612+
ResourceName: resourceName,
613+
ImportState: true,
614+
ImportStateVerify: true,
615+
ImportStateVerifyIgnore: []string{"disk_list"},
616+
},
617+
},
618+
})
619+
}
620+
621+
func TestAccNutanixVirtualMachine_SecureBootWithNoMachineType(t *testing.T) {
622+
r := acctest.RandInt()
623+
name := fmt.Sprintf("test-vm-%d", r)
624+
desc := "this is vm desc"
625+
memory := "200"
626+
resource.Test(t, resource.TestCase{
627+
PreCheck: func() { testAccPreCheck(t) },
628+
Providers: testAccProviders,
629+
CheckDestroy: testAccCheckNutanixVirtualMachineDestroy,
630+
Steps: []resource.TestStep{
631+
{
632+
Config: testAccNutanixVMConfigWithSecureBootWithNoMachineType(name, desc, memory),
633+
ExpectError: regexp.MustCompile("Machine type must be set to Q35 for secure boot."),
634+
},
635+
},
636+
})
637+
}
638+
566639
func testAccCheckNutanixVirtualMachineExists(n string) resource.TestCheckFunc {
567640
return func(s *terraform.State) error {
568641
rs, ok := s.RootModule().Resources[n]
@@ -1447,3 +1520,85 @@ func testAccNutanixVMConfigSysprepCustomKeyValues(r int) string {
14471520
}
14481521
`, r)
14491522
}
1523+
1524+
func testAccNutanixVMConfigWithSecureBoot(name, desc, mem string) string {
1525+
return fmt.Sprintf(`
1526+
data "nutanix_clusters" "clusters" {}
1527+
1528+
locals {
1529+
cluster1 = "${data.nutanix_clusters.clusters.entities.0.service_list.0 == "PRISM_CENTRAL"
1530+
? data.nutanix_clusters.clusters.entities.1.metadata.uuid : data.nutanix_clusters.clusters.entities.0.metadata.uuid}"
1531+
}
1532+
1533+
resource "nutanix_virtual_machine" "test" {
1534+
name = "%[1]s"
1535+
description = "%[2]s"
1536+
num_vcpus_per_socket = 3
1537+
num_sockets = 1
1538+
memory_size_mib = %[3]s
1539+
1540+
cluster_uuid = "${local.cluster1}"
1541+
1542+
boot_type = "SECURE_BOOT"
1543+
boot_device_order_list = ["DISK", "CDROM"]
1544+
machine_type = "Q35"
1545+
1546+
disk_list {
1547+
disk_size_mib = 40240
1548+
device_properties {
1549+
device_type = "DISK"
1550+
disk_address = {
1551+
"adapter_type" = "SCSI"
1552+
"device_index" = "0"
1553+
}
1554+
}
1555+
}
1556+
disk_list {
1557+
disk_size_mib = 40240
1558+
device_properties {
1559+
device_type = "DISK"
1560+
disk_address = {
1561+
"adapter_type" = "SCSI"
1562+
"device_index" = "1"
1563+
}
1564+
}
1565+
}
1566+
}
1567+
1568+
`, name, desc, mem)
1569+
}
1570+
1571+
func testAccNutanixVMConfigWithSecureBootWithNoMachineType(name, desc, mem string) string {
1572+
return fmt.Sprintf(`
1573+
data "nutanix_clusters" "clusters" {}
1574+
1575+
locals {
1576+
cluster1 = "${data.nutanix_clusters.clusters.entities.0.service_list.0 == "PRISM_CENTRAL"
1577+
? data.nutanix_clusters.clusters.entities.1.metadata.uuid : data.nutanix_clusters.clusters.entities.0.metadata.uuid}"
1578+
}
1579+
1580+
resource "nutanix_virtual_machine" "test" {
1581+
name = "%[1]s"
1582+
description = "%[2]s"
1583+
num_vcpus_per_socket = 3
1584+
num_sockets = 1
1585+
memory_size_mib = %[3]s
1586+
1587+
cluster_uuid = "${local.cluster1}"
1588+
1589+
boot_type = "SECURE_BOOT"
1590+
boot_device_order_list = ["DISK", "CDROM"]
1591+
disk_list {
1592+
disk_size_mib = 40240
1593+
device_properties {
1594+
device_type = "DISK"
1595+
disk_address = {
1596+
"adapter_type" = "SCSI"
1597+
"device_index" = "0"
1598+
}
1599+
}
1600+
}
1601+
}
1602+
1603+
`, name, desc, mem)
1604+
}

0 commit comments

Comments
 (0)