@@ -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" {
900898func 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+
948994const testAccCheckVSphereVirtualMachineConfig_updateAddDisks = `
949995resource "vsphere_virtual_machine" "foo" {
950996 name = "terraform-test"
0 commit comments