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.
This commit is contained in:
parent
9a39057a4f
commit
6aa3bb574a
|
@ -925,10 +925,14 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{})
|
||||||
|
|
||||||
if state == types.VirtualMachinePowerStatePoweredOn {
|
if state == types.VirtualMachinePowerStatePoweredOn {
|
||||||
// wait for interfaces to appear
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] Successfully waited for interfaces to appear")
|
||||||
}
|
}
|
||||||
|
|
||||||
var mvm mo.VirtualMachine
|
var mvm mo.VirtualMachine
|
||||||
|
|
|
@ -869,17 +869,15 @@ func TestAccVSphereVirtualMachine_updateVcpu(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccCheckVSphereVirtualMachineConfig_ipv4Andipv6 = `
|
const testAccCheckVSphereVirtualMachineConfig_ipv6 = `
|
||||||
resource "vsphere_virtual_machine" "ipv4ipv6" {
|
resource "vsphere_virtual_machine" "ipv6" {
|
||||||
name = "terraform-test-ipv4-ipv6"
|
name = "terraform-test-ipv6"
|
||||||
%s
|
%s
|
||||||
vcpu = 2
|
vcpu = 2
|
||||||
memory = 1024
|
memory = 1024
|
||||||
network_interface {
|
network_interface {
|
||||||
label = "%s"
|
label = "%s"
|
||||||
ipv4_address = "%s"
|
%s
|
||||||
ipv4_prefix_length = %s
|
|
||||||
ipv4_gateway = "%s"
|
|
||||||
ipv6_address = "%s"
|
ipv6_address = "%s"
|
||||||
ipv6_prefix_length = 64
|
ipv6_prefix_length = 64
|
||||||
ipv6_gateway = "%s"
|
ipv6_gateway = "%s"
|
||||||
|
@ -900,24 +898,28 @@ resource "vsphere_virtual_machine" "ipv4ipv6" {
|
||||||
func TestAccVSphereVirtualMachine_ipv4Andipv6(t *testing.T) {
|
func TestAccVSphereVirtualMachine_ipv4Andipv6(t *testing.T) {
|
||||||
var vm virtualMachine
|
var vm virtualMachine
|
||||||
data := setupTemplateBasicBodyVars()
|
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 :=
|
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??
|
// FIXME test for this or warn??
|
||||||
ipv6Address := os.Getenv("VSPHERE_IPV6_ADDRESS")
|
ipv6Address := os.Getenv("VSPHERE_IPV6_ADDRESS")
|
||||||
ipv6Gateway := os.Getenv("VSPHERE_IPV6_GATEWAY")
|
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(
|
config := fmt.Sprintf(
|
||||||
testAccCheckVSphereVirtualMachineConfig_ipv4Andipv6,
|
testAccCheckVSphereVirtualMachineConfig_ipv6,
|
||||||
data.locationOpt,
|
data.locationOpt,
|
||||||
data.label,
|
data.label,
|
||||||
data.ipv4IpAddress,
|
ipv4Settings,
|
||||||
data.ipv4Prefix,
|
|
||||||
data.ipv4Gateway,
|
|
||||||
ipv6Address,
|
ipv6Address,
|
||||||
ipv6Gateway,
|
ipv6Gateway,
|
||||||
data.datastoreOpt,
|
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 = `
|
const testAccCheckVSphereVirtualMachineConfig_updateAddDisks = `
|
||||||
resource "vsphere_virtual_machine" "foo" {
|
resource "vsphere_virtual_machine" "foo" {
|
||||||
name = "terraform-test"
|
name = "terraform-test"
|
||||||
|
|
Loading…
Reference in New Issue