@@ -517,6 +517,168 @@ func TestAccVSphereVirtualMachine_createWithExistingVmdk(t *testing.T) {
517517 })
518518}
519519
520+ func TestAccVSphereVirtualMachine_updateMemory (t * testing.T ) {
521+ var vm virtualMachine
522+ var locationOpt string
523+ var datastoreOpt string
524+
525+ if v := os .Getenv ("VSPHERE_DATACENTER" ); v != "" {
526+ locationOpt += fmt .Sprintf (" datacenter = \" %s\" \n " , v )
527+ }
528+ if v := os .Getenv ("VSPHERE_CLUSTER" ); v != "" {
529+ locationOpt += fmt .Sprintf (" cluster = \" %s\" \n " , v )
530+ }
531+ if v := os .Getenv ("VSPHERE_RESOURCE_POOL" ); v != "" {
532+ locationOpt += fmt .Sprintf (" resource_pool = \" %s\" \n " , v )
533+ }
534+ if v := os .Getenv ("VSPHERE_DATASTORE" ); v != "" {
535+ datastoreOpt = fmt .Sprintf (" datastore = \" %s\" \n " , v )
536+ }
537+ template := os .Getenv ("VSPHERE_TEMPLATE" )
538+ label := os .Getenv ("VSPHERE_NETWORK_LABEL_DHCP" )
539+
540+ resource .Test (t , resource.TestCase {
541+ PreCheck : func () { testAccPreCheck (t ) },
542+ Providers : testAccProviders ,
543+ CheckDestroy : testAccCheckVSphereVirtualMachineDestroy ,
544+ Steps : []resource.TestStep {
545+ resource.TestStep {
546+ Config : fmt .Sprintf (
547+ testAccCheckVSphereVirtualMachineConfig_updateMemoryInitial ,
548+ locationOpt ,
549+ label ,
550+ datastoreOpt ,
551+ template ,
552+ ),
553+ Check : resource .ComposeTestCheckFunc (
554+ testAccCheckVSphereVirtualMachineExists ("vsphere_virtual_machine.bar" , & vm ),
555+ resource .TestCheckResourceAttr (
556+ "vsphere_virtual_machine.bar" , "name" , "terraform-test" ),
557+ resource .TestCheckResourceAttr (
558+ "vsphere_virtual_machine.bar" , "vcpu" , "2" ),
559+ resource .TestCheckResourceAttr (
560+ "vsphere_virtual_machine.bar" , "memory" , "4096" ),
561+ resource .TestCheckResourceAttr (
562+ "vsphere_virtual_machine.bar" , "disk.#" , "1" ),
563+ resource .TestCheckResourceAttr (
564+ "vsphere_virtual_machine.bar" , "disk.0.template" , template ),
565+ resource .TestCheckResourceAttr (
566+ "vsphere_virtual_machine.bar" , "network_interface.#" , "1" ),
567+ resource .TestCheckResourceAttr (
568+ "vsphere_virtual_machine.bar" , "network_interface.0.label" , label ),
569+ ),
570+ },
571+ resource.TestStep {
572+ Config : fmt .Sprintf (
573+ testAccCheckVSphereVirtualMachineConfig_updateMemoryUpdate ,
574+ locationOpt ,
575+ label ,
576+ datastoreOpt ,
577+ template ,
578+ ),
579+ Check : resource .ComposeTestCheckFunc (
580+ testAccCheckVSphereVirtualMachineExists ("vsphere_virtual_machine.bar" , & vm ),
581+ resource .TestCheckResourceAttr (
582+ "vsphere_virtual_machine.bar" , "name" , "terraform-test" ),
583+ resource .TestCheckResourceAttr (
584+ "vsphere_virtual_machine.bar" , "vcpu" , "2" ),
585+ resource .TestCheckResourceAttr (
586+ "vsphere_virtual_machine.bar" , "memory" , "2048" ),
587+ resource .TestCheckResourceAttr (
588+ "vsphere_virtual_machine.bar" , "disk.#" , "1" ),
589+ resource .TestCheckResourceAttr (
590+ "vsphere_virtual_machine.bar" , "disk.0.template" , template ),
591+ resource .TestCheckResourceAttr (
592+ "vsphere_virtual_machine.bar" , "network_interface.#" , "1" ),
593+ resource .TestCheckResourceAttr (
594+ "vsphere_virtual_machine.bar" , "network_interface.0.label" , label ),
595+ ),
596+ },
597+ },
598+ })
599+ }
600+
601+ func TestAccVSphereVirtualMachine_updateVcpu (t * testing.T ) {
602+ var vm virtualMachine
603+ var locationOpt string
604+ var datastoreOpt string
605+
606+ if v := os .Getenv ("VSPHERE_DATACENTER" ); v != "" {
607+ locationOpt += fmt .Sprintf (" datacenter = \" %s\" \n " , v )
608+ }
609+ if v := os .Getenv ("VSPHERE_CLUSTER" ); v != "" {
610+ locationOpt += fmt .Sprintf (" cluster = \" %s\" \n " , v )
611+ }
612+ if v := os .Getenv ("VSPHERE_RESOURCE_POOL" ); v != "" {
613+ locationOpt += fmt .Sprintf (" resource_pool = \" %s\" \n " , v )
614+ }
615+ if v := os .Getenv ("VSPHERE_DATASTORE" ); v != "" {
616+ datastoreOpt = fmt .Sprintf (" datastore = \" %s\" \n " , v )
617+ }
618+ template := os .Getenv ("VSPHERE_TEMPLATE" )
619+ label := os .Getenv ("VSPHERE_NETWORK_LABEL_DHCP" )
620+
621+ resource .Test (t , resource.TestCase {
622+ PreCheck : func () { testAccPreCheck (t ) },
623+ Providers : testAccProviders ,
624+ CheckDestroy : testAccCheckVSphereVirtualMachineDestroy ,
625+ Steps : []resource.TestStep {
626+ resource.TestStep {
627+ Config : fmt .Sprintf (
628+ testAccCheckVSphereVirtualMachineConfig_updateVcpuInitial ,
629+ locationOpt ,
630+ label ,
631+ datastoreOpt ,
632+ template ,
633+ ),
634+ Check : resource .ComposeTestCheckFunc (
635+ testAccCheckVSphereVirtualMachineExists ("vsphere_virtual_machine.bar" , & vm ),
636+ resource .TestCheckResourceAttr (
637+ "vsphere_virtual_machine.bar" , "name" , "terraform-test" ),
638+ resource .TestCheckResourceAttr (
639+ "vsphere_virtual_machine.bar" , "vcpu" , "2" ),
640+ resource .TestCheckResourceAttr (
641+ "vsphere_virtual_machine.bar" , "memory" , "4096" ),
642+ resource .TestCheckResourceAttr (
643+ "vsphere_virtual_machine.bar" , "disk.#" , "1" ),
644+ resource .TestCheckResourceAttr (
645+ "vsphere_virtual_machine.bar" , "disk.0.template" , template ),
646+ resource .TestCheckResourceAttr (
647+ "vsphere_virtual_machine.bar" , "network_interface.#" , "1" ),
648+ resource .TestCheckResourceAttr (
649+ "vsphere_virtual_machine.bar" , "network_interface.0.label" , label ),
650+ ),
651+ },
652+ resource.TestStep {
653+ Config : fmt .Sprintf (
654+ testAccCheckVSphereVirtualMachineConfig_updateVcpuUpdate ,
655+ locationOpt ,
656+ label ,
657+ datastoreOpt ,
658+ template ,
659+ ),
660+ Check : resource .ComposeTestCheckFunc (
661+ testAccCheckVSphereVirtualMachineExists ("vsphere_virtual_machine.bar" , & vm ),
662+ resource .TestCheckResourceAttr (
663+ "vsphere_virtual_machine.bar" , "name" , "terraform-test" ),
664+ resource .TestCheckResourceAttr (
665+ "vsphere_virtual_machine.bar" , "vcpu" , "4" ),
666+ resource .TestCheckResourceAttr (
667+ "vsphere_virtual_machine.bar" , "memory" , "4096" ),
668+ resource .TestCheckResourceAttr (
669+ "vsphere_virtual_machine.bar" , "disk.#" , "1" ),
670+ resource .TestCheckResourceAttr (
671+ "vsphere_virtual_machine.bar" , "disk.0.template" , template ),
672+ resource .TestCheckResourceAttr (
673+ "vsphere_virtual_machine.bar" , "network_interface.#" , "1" ),
674+ resource .TestCheckResourceAttr (
675+ "vsphere_virtual_machine.bar" , "network_interface.0.label" , label ),
676+ ),
677+ },
678+ },
679+ })
680+ }
681+
520682func testAccCheckVSphereVirtualMachineDestroy (s * terraform.State ) error {
521683 client := testAccProvider .Meta ().(* govmomi.Client )
522684 finder := find .NewFinder (client .Client , true )
@@ -853,3 +1015,67 @@ resource "vsphere_virtual_machine" "with_existing_vmdk" {
8531015 }
8541016}
8551017`
1018+
1019+ const testAccCheckVSphereVirtualMachineConfig_updateMemoryInitial = `
1020+ resource "vsphere_virtual_machine" "bar" {
1021+ name = "terraform-test"
1022+ %s
1023+ vcpu = 2
1024+ memory = 4096
1025+ network_interface {
1026+ label = "%s"
1027+ }
1028+ disk {
1029+ %s
1030+ template = "%s"
1031+ }
1032+ }
1033+ `
1034+
1035+ const testAccCheckVSphereVirtualMachineConfig_updateMemoryUpdate = `
1036+ resource "vsphere_virtual_machine" "bar" {
1037+ name = "terraform-test"
1038+ %s
1039+ vcpu = 2
1040+ memory = 2048
1041+ network_interface {
1042+ label = "%s"
1043+ }
1044+ disk {
1045+ %s
1046+ template = "%s"
1047+ }
1048+ }
1049+ `
1050+
1051+ const testAccCheckVSphereVirtualMachineConfig_updateVcpuInitial = `
1052+ resource "vsphere_virtual_machine" "bar" {
1053+ name = "terraform-test"
1054+ %s
1055+ vcpu = 2
1056+ memory = 4096
1057+ network_interface {
1058+ label = "%s"
1059+ }
1060+ disk {
1061+ %s
1062+ template = "%s"
1063+ }
1064+ }
1065+ `
1066+
1067+ const testAccCheckVSphereVirtualMachineConfig_updateVcpuUpdate = `
1068+ resource "vsphere_virtual_machine" "bar" {
1069+ name = "terraform-test"
1070+ %s
1071+ vcpu = 4
1072+ memory = 4096
1073+ network_interface {
1074+ label = "%s"
1075+ }
1076+ disk {
1077+ %s
1078+ template = "%s"
1079+ }
1080+ }
1081+ `
0 commit comments