From 4c6404d0129b9003aef566f5d0d3e9b4c1139e73 Mon Sep 17 00:00:00 2001 From: Sandeep Sidhu Date: Wed, 24 May 2017 17:08:40 +0100 Subject: [PATCH] provider/vsphere: Exposing moid value from vm resource (#14793) * Exposing moid value from vm resource moid value is needed by NSX resources, like security tag, when we attached security tags to a VMs, so needed before we commit NSX provider. * fixing gofmt issue * Updating docs regarding new exported moid attribute. --- .../resource_vsphere_virtual_machine.go | 20 +++++++++++++++++++ .../vsphere/r/virtual_machine.html.markdown | 1 + 2 files changed, 21 insertions(+) diff --git a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go index 816385867..15e291a38 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 05f609cef..ad2f89040 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.