From a29a47eb04ce9d306fb42be0c035a13f44473021 Mon Sep 17 00:00:00 2001 From: sandeep-sidhu Date: Wed, 24 May 2017 14:04:45 +0100 Subject: [PATCH 1/3] 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. --- .../resource_vsphere_virtual_machine.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go index 816385867277..72162e7be4a0 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 { From 952164cd6cdef01a11187514c82fa1c2c3b023c8 Mon Sep 17 00:00:00 2001 From: sandeep-sidhu Date: Wed, 24 May 2017 14:16:10 +0100 Subject: [PATCH 2/3] fixing gofmt issue --- builtin/providers/vsphere/resource_vsphere_virtual_machine.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go index 72162e7be4a0..15e291a3890a 100644 --- a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go +++ b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go @@ -98,7 +98,7 @@ type virtualMachine struct { linkedClone bool skipCustomization bool enableDiskUUID bool - moid string + moid string windowsOptionalConfig windowsOptConfig customConfigurations map[string](types.AnyType) } From a9ad5b0ef1ad6b39229502479f3d89ccb4c782f3 Mon Sep 17 00:00:00 2001 From: sandeep-sidhu Date: Wed, 24 May 2017 16:32:14 +0100 Subject: [PATCH 3/3] Updating docs regarding new exported moid attribute. --- .../docs/providers/vsphere/r/virtual_machine.html.markdown | 1 + 1 file changed, 1 insertion(+) 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.