From 8390154968090725ea8de70f21b08eee8c9014ac Mon Sep 17 00:00:00 2001 From: Takaaki Furukawa Date: Mon, 26 Oct 2015 10:32:19 +0900 Subject: [PATCH] provider/vsphere: Fix d.SetConnInfo error in case of a missing IP address --- .../vsphere/resource_vsphere_virtual_machine.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go index c6b1292ac..eab65aba5 100644 --- a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go +++ b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go @@ -389,6 +389,7 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{}) networkInterfaces = append(networkInterfaces, networkInterface) } } + log.Printf("[DEBUG] networkInterfaces: %#v", networkInterfaces) err = d.Set("network_interface", networkInterfaces) if err != nil { return fmt.Errorf("Invalid network interfaces to set: %#v", networkInterfaces) @@ -420,10 +421,12 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{}) d.Set("datastore", rootDatastore) // Initialize the connection info - d.SetConnInfo(map[string]string{ - "type": "ssh", - "host": networkInterfaces[0]["ip_address"].(string), - }) + if len(networkInterfaces) > 0 { + d.SetConnInfo(map[string]string{ + "type": "ssh", + "host": networkInterfaces[0]["ip_address"].(string), + }) + } return nil }