From 6aa3bb574aaccb98c6fa04ecc82d1805166b9fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristinn=20=C3=96rn=20Sigur=C3=B0sson?= Date: Mon, 15 Aug 2016 18:43:54 +0200 Subject: [PATCH] provider/vSphere: Fix for IPv6 only environment creation. (#7643) The code only waited until one or more IPv4 interfaces came online. If you only had IPv6 interfaces attached to your machine, then the machine creation process would completely stall. --- .../resource_vsphere_virtual_machine.go | 6 +- .../resource_vsphere_virtual_machine_test.go | 72 +++++++++++++++---- 2 files changed, 64 insertions(+), 14 deletions(-) diff --git a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go index 3de90d502..1fc84789b 100644 --- a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go +++ b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go @@ -925,10 +925,14 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{}) if state == types.VirtualMachinePowerStatePoweredOn { // wait for interfaces to appear - _, err = vm.WaitForNetIP(context.TODO(), true) + log.Printf("[DEBUG] Waiting for interfaces to appear") + + _, err = vm.WaitForNetIP(context.TODO(), false) if err != nil { return err } + + log.Printf("[DEBUG] Successfully waited for interfaces to appear") } var mvm mo.VirtualMachine diff --git a/builtin/providers/vsphere/resource_vsphere_virtual_machine_test.go b/builtin/providers/vsphere/resource_vsphere_virtual_machine_test.go index a8c4602ab..7ce5869d5 100644 --- a/builtin/providers/vsphere/resource_vsphere_virtual_machine_test.go +++ b/builtin/providers/vsphere/resource_vsphere_virtual_machine_test.go @@ -869,17 +869,15 @@ func TestAccVSphereVirtualMachine_updateVcpu(t *testing.T) { }) } -const testAccCheckVSphereVirtualMachineConfig_ipv4Andipv6 = ` -resource "vsphere_virtual_machine" "ipv4ipv6" { - name = "terraform-test-ipv4-ipv6" +const testAccCheckVSphereVirtualMachineConfig_ipv6 = ` +resource "vsphere_virtual_machine" "ipv6" { + name = "terraform-test-ipv6" %s vcpu = 2 memory = 1024 network_interface { label = "%s" - ipv4_address = "%s" - ipv4_prefix_length = %s - ipv4_gateway = "%s" + %s ipv6_address = "%s" ipv6_prefix_length = 64 ipv6_gateway = "%s" @@ -900,24 +898,28 @@ resource "vsphere_virtual_machine" "ipv4ipv6" { func TestAccVSphereVirtualMachine_ipv4Andipv6(t *testing.T) { var vm virtualMachine data := setupTemplateBasicBodyVars() - log.Printf("[DEBUG] template= %s", testAccCheckVSphereVirtualMachineConfig_ipv4Andipv6) + log.Printf("[DEBUG] template= %s", testAccCheckVSphereVirtualMachineConfig_ipv6) - vmName := "vsphere_virtual_machine.ipv4ipv6" + vmName := "vsphere_virtual_machine.ipv6" test_exists, test_name, test_cpu, test_uuid, test_mem, test_num_disk, test_num_of_nic, test_nic_label := - TestFuncData{vm: vm, label: data.label, vmName: vmName, numDisks: "2", vmResource: "terraform-test-ipv4-ipv6"}.testCheckFuncBasic() + TestFuncData{vm: vm, label: data.label, vmName: vmName, numDisks: "2", vmResource: "terraform-test-ipv6"}.testCheckFuncBasic() // FIXME test for this or warn?? ipv6Address := os.Getenv("VSPHERE_IPV6_ADDRESS") ipv6Gateway := os.Getenv("VSPHERE_IPV6_GATEWAY") + ipv4Settings := fmt.Sprintf(` + ipv4_address = "%s" + ipv4_prefix_length = %s + ipv4_gateway = "%s" + `, data.ipv4IpAddress, data.ipv4Prefix, data.ipv4Gateway) + config := fmt.Sprintf( - testAccCheckVSphereVirtualMachineConfig_ipv4Andipv6, + testAccCheckVSphereVirtualMachineConfig_ipv6, data.locationOpt, data.label, - data.ipv4IpAddress, - data.ipv4Prefix, - data.ipv4Gateway, + ipv4Settings, ipv6Address, ipv6Gateway, data.datastoreOpt, @@ -945,6 +947,50 @@ func TestAccVSphereVirtualMachine_ipv4Andipv6(t *testing.T) { }) } +func TestAccVSphereVirtualMachine_ipv6Only(t *testing.T) { + var vm virtualMachine + data := setupTemplateBasicBodyVars() + log.Printf("[DEBUG] template= %s", testAccCheckVSphereVirtualMachineConfig_ipv6) + + vmName := "vsphere_virtual_machine.ipv6" + + test_exists, test_name, test_cpu, test_uuid, test_mem, test_num_disk, test_num_of_nic, test_nic_label := + TestFuncData{vm: vm, label: data.label, vmName: vmName, numDisks: "2", vmResource: "terraform-test-ipv6"}.testCheckFuncBasic() + + // Checks for this will be handled when this code is merged with https://github.com/hashicorp/terraform/pull/7575. + ipv6Address := os.Getenv("VSPHERE_IPV6_ADDRESS") + ipv6Gateway := os.Getenv("VSPHERE_IPV6_GATEWAY") + + config := fmt.Sprintf( + testAccCheckVSphereVirtualMachineConfig_ipv6, + data.locationOpt, + data.label, + "", + ipv6Address, + ipv6Gateway, + data.datastoreOpt, + data.template, + ) + + log.Printf("[DEBUG] template config= %s", config) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVSphereVirtualMachineDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + Check: resource.ComposeTestCheckFunc( + test_exists, test_name, test_cpu, test_uuid, test_mem, test_num_disk, test_num_of_nic, test_nic_label, + resource.TestCheckResourceAttr(vmName, "network_interface.0.ipv6_address", ipv6Address), + resource.TestCheckResourceAttr(vmName, "network_interface.0.ipv6_gateway", ipv6Gateway), + ), + }, + }, + }) +} + const testAccCheckVSphereVirtualMachineConfig_updateAddDisks = ` resource "vsphere_virtual_machine" "foo" { name = "terraform-test"