Skip to content

Commit 6aa3bb5

Browse files
kristinncatsby
authored andcommitted
provider/vSphere: Fix for IPv6 only environment creation. (hashicorp#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.
1 parent 9a39057 commit 6aa3bb5

2 files changed

Lines changed: 64 additions & 14 deletions

File tree

builtin/providers/vsphere/resource_vsphere_virtual_machine.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,10 +925,14 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{})
925925

926926
if state == types.VirtualMachinePowerStatePoweredOn {
927927
// wait for interfaces to appear
928-
_, err = vm.WaitForNetIP(context.TODO(), true)
928+
log.Printf("[DEBUG] Waiting for interfaces to appear")
929+
930+
_, err = vm.WaitForNetIP(context.TODO(), false)
929931
if err != nil {
930932
return err
931933
}
934+
935+
log.Printf("[DEBUG] Successfully waited for interfaces to appear")
932936
}
933937

934938
var mvm mo.VirtualMachine

builtin/providers/vsphere/resource_vsphere_virtual_machine_test.go

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -869,17 +869,15 @@ func TestAccVSphereVirtualMachine_updateVcpu(t *testing.T) {
869869
})
870870
}
871871

872-
const testAccCheckVSphereVirtualMachineConfig_ipv4Andipv6 = `
873-
resource "vsphere_virtual_machine" "ipv4ipv6" {
874-
name = "terraform-test-ipv4-ipv6"
872+
const testAccCheckVSphereVirtualMachineConfig_ipv6 = `
873+
resource "vsphere_virtual_machine" "ipv6" {
874+
name = "terraform-test-ipv6"
875875
%s
876876
vcpu = 2
877877
memory = 1024
878878
network_interface {
879879
label = "%s"
880-
ipv4_address = "%s"
881-
ipv4_prefix_length = %s
882-
ipv4_gateway = "%s"
880+
%s
883881
ipv6_address = "%s"
884882
ipv6_prefix_length = 64
885883
ipv6_gateway = "%s"
@@ -900,24 +898,28 @@ resource "vsphere_virtual_machine" "ipv4ipv6" {
900898
func TestAccVSphereVirtualMachine_ipv4Andipv6(t *testing.T) {
901899
var vm virtualMachine
902900
data := setupTemplateBasicBodyVars()
903-
log.Printf("[DEBUG] template= %s", testAccCheckVSphereVirtualMachineConfig_ipv4Andipv6)
901+
log.Printf("[DEBUG] template= %s", testAccCheckVSphereVirtualMachineConfig_ipv6)
904902

905-
vmName := "vsphere_virtual_machine.ipv4ipv6"
903+
vmName := "vsphere_virtual_machine.ipv6"
906904

907905
test_exists, test_name, test_cpu, test_uuid, test_mem, test_num_disk, test_num_of_nic, test_nic_label :=
908-
TestFuncData{vm: vm, label: data.label, vmName: vmName, numDisks: "2", vmResource: "terraform-test-ipv4-ipv6"}.testCheckFuncBasic()
906+
TestFuncData{vm: vm, label: data.label, vmName: vmName, numDisks: "2", vmResource: "terraform-test-ipv6"}.testCheckFuncBasic()
909907

910908
// FIXME test for this or warn??
911909
ipv6Address := os.Getenv("VSPHERE_IPV6_ADDRESS")
912910
ipv6Gateway := os.Getenv("VSPHERE_IPV6_GATEWAY")
913911

912+
ipv4Settings := fmt.Sprintf(`
913+
ipv4_address = "%s"
914+
ipv4_prefix_length = %s
915+
ipv4_gateway = "%s"
916+
`, data.ipv4IpAddress, data.ipv4Prefix, data.ipv4Gateway)
917+
914918
config := fmt.Sprintf(
915-
testAccCheckVSphereVirtualMachineConfig_ipv4Andipv6,
919+
testAccCheckVSphereVirtualMachineConfig_ipv6,
916920
data.locationOpt,
917921
data.label,
918-
data.ipv4IpAddress,
919-
data.ipv4Prefix,
920-
data.ipv4Gateway,
922+
ipv4Settings,
921923
ipv6Address,
922924
ipv6Gateway,
923925
data.datastoreOpt,
@@ -945,6 +947,50 @@ func TestAccVSphereVirtualMachine_ipv4Andipv6(t *testing.T) {
945947
})
946948
}
947949

950+
func TestAccVSphereVirtualMachine_ipv6Only(t *testing.T) {
951+
var vm virtualMachine
952+
data := setupTemplateBasicBodyVars()
953+
log.Printf("[DEBUG] template= %s", testAccCheckVSphereVirtualMachineConfig_ipv6)
954+
955+
vmName := "vsphere_virtual_machine.ipv6"
956+
957+
test_exists, test_name, test_cpu, test_uuid, test_mem, test_num_disk, test_num_of_nic, test_nic_label :=
958+
TestFuncData{vm: vm, label: data.label, vmName: vmName, numDisks: "2", vmResource: "terraform-test-ipv6"}.testCheckFuncBasic()
959+
960+
// Checks for this will be handled when this code is merged with https://github.com/hashicorp/terraform/pull/7575.
961+
ipv6Address := os.Getenv("VSPHERE_IPV6_ADDRESS")
962+
ipv6Gateway := os.Getenv("VSPHERE_IPV6_GATEWAY")
963+
964+
config := fmt.Sprintf(
965+
testAccCheckVSphereVirtualMachineConfig_ipv6,
966+
data.locationOpt,
967+
data.label,
968+
"",
969+
ipv6Address,
970+
ipv6Gateway,
971+
data.datastoreOpt,
972+
data.template,
973+
)
974+
975+
log.Printf("[DEBUG] template config= %s", config)
976+
977+
resource.Test(t, resource.TestCase{
978+
PreCheck: func() { testAccPreCheck(t) },
979+
Providers: testAccProviders,
980+
CheckDestroy: testAccCheckVSphereVirtualMachineDestroy,
981+
Steps: []resource.TestStep{
982+
resource.TestStep{
983+
Config: config,
984+
Check: resource.ComposeTestCheckFunc(
985+
test_exists, test_name, test_cpu, test_uuid, test_mem, test_num_disk, test_num_of_nic, test_nic_label,
986+
resource.TestCheckResourceAttr(vmName, "network_interface.0.ipv6_address", ipv6Address),
987+
resource.TestCheckResourceAttr(vmName, "network_interface.0.ipv6_gateway", ipv6Gateway),
988+
),
989+
},
990+
},
991+
})
992+
}
993+
948994
const testAccCheckVSphereVirtualMachineConfig_updateAddDisks = `
949995
resource "vsphere_virtual_machine" "foo" {
950996
name = "terraform-test"

0 commit comments

Comments
 (0)