@ -517,6 +517,168 @@ func TestAccVSphereVirtualMachine_createWithExistingVmdk(t *testing.T) {
} )
}
func TestAccVSphereVirtualMachine_updateMemory ( t * testing . T ) {
var vm virtualMachine
var locationOpt string
var datastoreOpt string
if v := os . Getenv ( "VSPHERE_DATACENTER" ) ; v != "" {
locationOpt += fmt . Sprintf ( " datacenter = \"%s\"\n" , v )
}
if v := os . Getenv ( "VSPHERE_CLUSTER" ) ; v != "" {
locationOpt += fmt . Sprintf ( " cluster = \"%s\"\n" , v )
}
if v := os . Getenv ( "VSPHERE_RESOURCE_POOL" ) ; v != "" {
locationOpt += fmt . Sprintf ( " resource_pool = \"%s\"\n" , v )
}
if v := os . Getenv ( "VSPHERE_DATASTORE" ) ; v != "" {
datastoreOpt = fmt . Sprintf ( " datastore = \"%s\"\n" , v )
}
template := os . Getenv ( "VSPHERE_TEMPLATE" )
label := os . Getenv ( "VSPHERE_NETWORK_LABEL_DHCP" )
resource . Test ( t , resource . TestCase {
PreCheck : func ( ) { testAccPreCheck ( t ) } ,
Providers : testAccProviders ,
CheckDestroy : testAccCheckVSphereVirtualMachineDestroy ,
Steps : [ ] resource . TestStep {
resource . TestStep {
Config : fmt . Sprintf (
testAccCheckVSphereVirtualMachineConfig_updateMemoryInitial ,
locationOpt ,
label ,
datastoreOpt ,
template ,
) ,
Check : resource . ComposeTestCheckFunc (
testAccCheckVSphereVirtualMachineExists ( "vsphere_virtual_machine.bar" , & vm ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "name" , "terraform-test" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "vcpu" , "2" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "memory" , "4096" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "disk.#" , "1" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "disk.0.template" , template ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "network_interface.#" , "1" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "network_interface.0.label" , label ) ,
) ,
} ,
resource . TestStep {
Config : fmt . Sprintf (
testAccCheckVSphereVirtualMachineConfig_updateMemoryUpdate ,
locationOpt ,
label ,
datastoreOpt ,
template ,
) ,
Check : resource . ComposeTestCheckFunc (
testAccCheckVSphereVirtualMachineExists ( "vsphere_virtual_machine.bar" , & vm ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "name" , "terraform-test" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "vcpu" , "2" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "memory" , "2048" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "disk.#" , "1" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "disk.0.template" , template ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "network_interface.#" , "1" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "network_interface.0.label" , label ) ,
) ,
} ,
} ,
} )
}
func TestAccVSphereVirtualMachine_updateVcpu ( t * testing . T ) {
var vm virtualMachine
var locationOpt string
var datastoreOpt string
if v := os . Getenv ( "VSPHERE_DATACENTER" ) ; v != "" {
locationOpt += fmt . Sprintf ( " datacenter = \"%s\"\n" , v )
}
if v := os . Getenv ( "VSPHERE_CLUSTER" ) ; v != "" {
locationOpt += fmt . Sprintf ( " cluster = \"%s\"\n" , v )
}
if v := os . Getenv ( "VSPHERE_RESOURCE_POOL" ) ; v != "" {
locationOpt += fmt . Sprintf ( " resource_pool = \"%s\"\n" , v )
}
if v := os . Getenv ( "VSPHERE_DATASTORE" ) ; v != "" {
datastoreOpt = fmt . Sprintf ( " datastore = \"%s\"\n" , v )
}
template := os . Getenv ( "VSPHERE_TEMPLATE" )
label := os . Getenv ( "VSPHERE_NETWORK_LABEL_DHCP" )
resource . Test ( t , resource . TestCase {
PreCheck : func ( ) { testAccPreCheck ( t ) } ,
Providers : testAccProviders ,
CheckDestroy : testAccCheckVSphereVirtualMachineDestroy ,
Steps : [ ] resource . TestStep {
resource . TestStep {
Config : fmt . Sprintf (
testAccCheckVSphereVirtualMachineConfig_updateVcpuInitial ,
locationOpt ,
label ,
datastoreOpt ,
template ,
) ,
Check : resource . ComposeTestCheckFunc (
testAccCheckVSphereVirtualMachineExists ( "vsphere_virtual_machine.bar" , & vm ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "name" , "terraform-test" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "vcpu" , "2" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "memory" , "4096" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "disk.#" , "1" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "disk.0.template" , template ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "network_interface.#" , "1" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "network_interface.0.label" , label ) ,
) ,
} ,
resource . TestStep {
Config : fmt . Sprintf (
testAccCheckVSphereVirtualMachineConfig_updateVcpuUpdate ,
locationOpt ,
label ,
datastoreOpt ,
template ,
) ,
Check : resource . ComposeTestCheckFunc (
testAccCheckVSphereVirtualMachineExists ( "vsphere_virtual_machine.bar" , & vm ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "name" , "terraform-test" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "vcpu" , "4" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "memory" , "4096" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "disk.#" , "1" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "disk.0.template" , template ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "network_interface.#" , "1" ) ,
resource . TestCheckResourceAttr (
"vsphere_virtual_machine.bar" , "network_interface.0.label" , label ) ,
) ,
} ,
} ,
} )
}
func testAccCheckVSphereVirtualMachineDestroy ( s * terraform . State ) error {
client := testAccProvider . Meta ( ) . ( * govmomi . Client )
finder := find . NewFinder ( client . Client , true )
@ -853,3 +1015,67 @@ resource "vsphere_virtual_machine" "with_existing_vmdk" {
}
}
`
const testAccCheckVSphereVirtualMachineConfig_updateMemoryInitial = `
resource "vsphere_virtual_machine" "bar" {
name = "terraform-test"
% s
vcpu = 2
memory = 4096
network_interface {
label = "%s"
}
disk {
% s
template = "%s"
}
}
`
const testAccCheckVSphereVirtualMachineConfig_updateMemoryUpdate = `
resource "vsphere_virtual_machine" "bar" {
name = "terraform-test"
% s
vcpu = 2
memory = 2048
network_interface {
label = "%s"
}
disk {
% s
template = "%s"
}
}
`
const testAccCheckVSphereVirtualMachineConfig_updateVcpuInitial = `
resource "vsphere_virtual_machine" "bar" {
name = "terraform-test"
% s
vcpu = 2
memory = 4096
network_interface {
label = "%s"
}
disk {
% s
template = "%s"
}
}
`
const testAccCheckVSphereVirtualMachineConfig_updateVcpuUpdate = `
resource "vsphere_virtual_machine" "bar" {
name = "terraform-test"
% s
vcpu = 4
memory = 4096
network_interface {
label = "%s"
}
disk {
% s
template = "%s"
}
}
`