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: Exposing moid value from vm resource #14793

Merged
merged 3 commits into from
May 24, 2017
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions builtin/providers/vsphere/resource_vsphere_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type virtualMachine struct {
linkedClone bool
skipCustomization bool
enableDiskUUID bool
moid string
windowsOptionalConfig windowsOptConfig
customConfigurations map[string](types.AnyType)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down