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.
This commit is contained in:
Sandeep Sidhu 2017-05-24 17:08:40 +01:00 committed by Paul Stack
parent 7c6c075640
commit 4c6404d012
2 changed files with 21 additions and 0 deletions

View File

@ -98,6 +98,7 @@ type virtualMachine struct {
linkedClone bool linkedClone bool
skipCustomization bool skipCustomization bool
enableDiskUUID bool enableDiskUUID bool
moid string
windowsOptionalConfig windowsOptConfig windowsOptionalConfig windowsOptConfig
customConfigurations map[string](types.AnyType) customConfigurations map[string](types.AnyType)
} }
@ -232,6 +233,11 @@ func resourceVSphereVirtualMachine() *schema.Resource {
Computed: true, Computed: true,
}, },
"moid": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"custom_configuration_parameters": &schema.Schema{ "custom_configuration_parameters": &schema.Schema{
Type: schema.TypeMap, Type: schema.TypeMap,
Optional: true, Optional: true,
@ -924,6 +930,13 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{})
return nil 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()) state, err := vm.PowerState(context.TODO())
if err != nil { if err != nil {
return err 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.Summary.Config - %#v", mvm.Config)
log.Printf("[DEBUG] mvm.Guest.Net - %#v", mvm.Guest.Net) 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) disks := make([]map[string]interface{}, 0)
templateDisk := make(map[string]interface{}, 1) templateDisk := make(map[string]interface{}, 1)
for _, device := range mvm.Config.Hardware.Device { for _, device := range mvm.Config.Hardware.Device {

View File

@ -138,6 +138,7 @@ The following attributes are exported:
* `id` - The instance ID. * `id` - The instance ID.
* `uuid` - The instance UUID. * `uuid` - The instance UUID.
* `moid` - The instance MOID (Managed Object Reference ID).
* `name` - See Argument Reference above. * `name` - See Argument Reference above.
* `vcpu` - See Argument Reference above. * `vcpu` - See Argument Reference above.
* `memory` - See Argument Reference above. * `memory` - See Argument Reference above.