From 01adcb18f3416be7e7fc02a9bec750375915968b Mon Sep 17 00:00:00 2001 From: Chris Love Date: Sun, 8 Nov 2015 18:49:49 -0700 Subject: [PATCH] adding new functional test --- .../resource_vsphere_virtual_machine_test.go | 83 ++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/builtin/providers/vsphere/resource_vsphere_virtual_machine_test.go b/builtin/providers/vsphere/resource_vsphere_virtual_machine_test.go index 66d6ea44f..2cae45fe4 100644 --- a/builtin/providers/vsphere/resource_vsphere_virtual_machine_test.go +++ b/builtin/providers/vsphere/resource_vsphere_virtual_machine_test.go @@ -127,6 +127,67 @@ func TestAccVSphereVirtualMachine_dhcp(t *testing.T) { }) } +func TestAccVSphereVirtualMachine_custom_configs(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_custom_configs, + locationOpt, + label, + datastoreOpt, + template, + ), + Check: resource.ComposeTestCheckFunc( + testAccCheckVSphereVirtualMachineExists("vsphere_virtual_machine.bar", &vm), + resource.TestCheckResourceAttr( + "vsphere_virtual_machine.car", "name", "terraform-test"), + resource.TestCheckResourceAttr( + "vsphere_virtual_machine.car", "vcpu", "2"), + resource.TestCheckResourceAttr( + "vsphere_virtual_machine.car", "memory", "4096"), + resource.TestCheckResourceAttr( + "vsphere_virtual_machine.car", "disk.#", "1"), + resource.TestCheckResourceAttr( + "vsphere_virtual_machine.car", "disk.0.template", template), + resource.TestCheckResourceAttr( + "vsphere_virtual_machine.car", "network_interface.#", "1"), + resource.TestCheckResourceAttr( + "vsphere_virtual_machine.car", "custom_configuration_parameters.foo", "bar"), + resource.TestCheckResourceAttr( + "vsphere_virtual_machine.car", "custom_configuration_parameters.car", "ferrai"), + resource.TestCheckResourceAttr( + "vsphere_virtual_machine.car", "custom_configuration_parameters.num", "42"), + 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) @@ -212,7 +273,6 @@ resource "vsphere_virtual_machine" "foo" { } } ` - const testAccCheckVSphereVirtualMachineConfig_dhcp = ` resource "vsphere_virtual_machine" "bar" { name = "terraform-test" @@ -228,3 +288,24 @@ resource "vsphere_virtual_machine" "bar" { } } ` + +const testAccCheckVSphereVirtualMachineConfig_custom_configs = ` +resource "vsphere_virtual_machine" "car" { + name = "terraform-test-custom" +%s + vcpu = 2 + memory = 4096 + network_interface { + label = "%s" + } + custom_configuration_parameters { + foo = "bar", + car = "ferrai", + num = 42 + } + disk { +%s + template = "%s" + } +} +`