diff --git a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go index 816385867277..15e291a3890a 100644 --- a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go +++ b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go @@ -98,6 +98,7 @@ type virtualMachine struct { linkedClone bool skipCustomization bool enableDiskUUID bool + moid string windowsOptionalConfig windowsOptConfig customConfigurations map[string](types.AnyType) } @@ -232,6 +233,11 @@ func resourceVSphereVirtualMachine() *schema.Resource { Computed: true, }, + "moid": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "custom_configuration_parameters": &schema.Schema{ Type: schema.TypeMap, Optional: true, @@ -924,6 +930,13 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{}) return nil } + err = d.Set("moid", vm.Reference().Value) + if err != nil { + return fmt.Errorf("Invalid moid to set: %#v", vm.Reference().Value) + } else { + log.Printf("[DEBUG] Set the moid: %#v", vm.Reference().Value) + } + state, err := vm.PowerState(context.TODO()) if err != nil { return err @@ -952,6 +965,13 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] mvm.Summary.Config - %#v", mvm.Config) log.Printf("[DEBUG] mvm.Guest.Net - %#v", mvm.Guest.Net) + err = d.Set("moid", mvm.Reference().Value) + if err != nil { + return fmt.Errorf("Invalid moid to set: %#v", mvm.Reference().Value) + } else { + log.Printf("[DEBUG] Set the moid: %#v", mvm.Reference().Value) + } + disks := make([]map[string]interface{}, 0) templateDisk := make(map[string]interface{}, 1) for _, device := range mvm.Config.Hardware.Device { diff --git a/website/source/docs/providers/vsphere/r/virtual_machine.html.markdown b/website/source/docs/providers/vsphere/r/virtual_machine.html.markdown index 05f609cef7b0..ad2f89040590 100644 --- a/website/source/docs/providers/vsphere/r/virtual_machine.html.markdown +++ b/website/source/docs/providers/vsphere/r/virtual_machine.html.markdown @@ -138,6 +138,7 @@ The following attributes are exported: * `id` - The instance ID. * `uuid` - The instance UUID. +* `moid` - The instance MOID (Managed Object Reference ID). * `name` - See Argument Reference above. * `vcpu` - See Argument Reference above. * `memory` - See Argument Reference above.