Skip to content

Commit

Permalink
Merge pull request #933 from terraform-providers/b-dont_set_dsid_with…
Browse files Browse the repository at this point in the history
…_dsc

Do not set the datastoreID in RelocateSpec when datastore_cluster is set
  • Loading branch information
aareet authored Jan 21, 2020
2 parents 51f1046 + 6ccf932 commit 3766b8c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions vsphere/resource_vsphere_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,13 +1451,15 @@ func resourceVSphereVirtualMachineUpdateLocation(d *schema.ResourceData, meta in
Pool: types.NewReference(pool.Reference()),
}

// Fetch the datastore
if dsID, ok := d.GetOk("datastore_id"); ok {
ds, err := datastore.FromID(client, dsID.(string))
if err != nil {
return fmt.Errorf("error locating datastore for VM: %s", err)
// Fetch the datastore only if a datastore_cluster is not set
if _, ok := d.GetOk("datastore_cluster_id"); !ok {
if dsID, ok := d.GetOk("datastore_id"); ok {
ds, err := datastore.FromID(client, dsID.(string))
if err != nil {
return fmt.Errorf("error locating datastore for VM: %s", err)
}
spec.Datastore = types.NewReference(ds.Reference())
}
spec.Datastore = types.NewReference(ds.Reference())
}

if hs != nil {
Expand Down

0 comments on commit 3766b8c

Please sign in to comment.