Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/vsphere: Fix missing ssh connection info #4283

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions builtin/providers/vsphere/resource_vsphere_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
}

func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{}) error {

log.Printf("[DEBUG] reading virtual machine: %#v", d)
client := meta.(*govmomi.Client)
dc, err := getDatacenter(client, d.Get("datacenter").(string))
Expand Down Expand Up @@ -484,6 +483,16 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Invalid network interfaces to set: %#v", networkInterfaces)
}

ip, err := vm.WaitForIP(context.TODO())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tkak shouldn't we be doing this earlier in the method? If we move it to before collector.RetrieveOne we may get better results. The thought that I have is that we are setting the network interfaces from Guest.Net and the data may not be populated until vm.WaitForIP returns. I am pushing a change to a branch on my repo, and maybe someone can test.

@ryanl-ee have you tested this change on this pull? I am still looking for a test bed unfortunately, but I will make the change that I mentioned to @tkak

if err != nil {
return err
}
log.Printf("[DEBUG] ip address: %v", ip)
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": ip,
})

var rootDatastore string
for _, v := range mvm.Datastore {
var md mo.Datastore
Expand Down Expand Up @@ -1021,7 +1030,7 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
if err != nil {
return err
}

log.Printf("[DEBUG] folder: %#v", vm.folder)
folder := dcFolders.VmFolder
if len(vm.folder) > 0 {
Expand Down