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

Pick default datastore for extra disks #897

Merged
merged 2 commits into from
Nov 11, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package virtualdevice
import (
"errors"
"fmt"
"github.com/terraform-providers/terraform-provider-vsphere/vsphere/internal/helper/virtualmachine"
"log"
"math"
"path"
Expand Down Expand Up @@ -1695,8 +1696,24 @@ func (r *DiskSubresource) assignBackingInfo(disk *types.VirtualDisk) error {
if dsID == "" || dsID == diskDatastoreComputedName {
// Default to the default datastore
dsID = r.rdd.Get("datastore_id").(string)
}

if dsID == "" {
vmObj, err := virtualmachine.FromUUID(r.client, r.rdd.Id())
if err != nil {
return err
}

vmprops, err := virtualmachine.Properties(vmObj)
if err != nil {
return err
}
if len(vmprops.Datastore) == 0 {
return fmt.Errorf("no datastore was set and was unable to find a default to fall back to")
}
dsID = vmprops.Datastore[0].Value

}
}
ds, err := datastore.FromID(r.client, dsID)
if err != nil {
return err
Expand Down