diff --git a/vsphere/resource_vsphere_virtual_machine.go b/vsphere/resource_vsphere_virtual_machine.go index 15e291a38..32c54489f 100644 --- a/vsphere/resource_vsphere_virtual_machine.go +++ b/vsphere/resource_vsphere_virtual_machine.go @@ -86,6 +86,7 @@ type virtualMachine struct { vcpu int32 memoryMb int64 memoryAllocation memoryAllocation + annotation string template string networkInterfaces []networkInterface hardDisks []hardDisk @@ -155,6 +156,11 @@ func resourceVSphereVirtualMachine() *schema.Resource { ForceNew: true, }, + "annotation": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + "datacenter": &schema.Schema{ Type: schema.TypeString, Optional: true, @@ -504,6 +510,11 @@ func resourceVSphereVirtualMachineUpdate(d *schema.ResourceData, meta interface{ rebootRequired = true } + if d.HasChange("annotation") { + configSpec.Annotation = d.Get("annotation").(string) + hasChanges = true + } + client := meta.(*govmomi.Client) dc, err := getDatacenter(client, d.Get("datacenter").(string)) if err != nil { @@ -696,6 +707,12 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{ vm.timeZone = v.(string) } + if v, ok := d.GetOk("annotation"); ok { + vm.annotation = v.(string) + } else { + vm.annotation = "" + } + if v, ok := d.GetOk("linked_clone"); ok { vm.linkedClone = v.(bool) } @@ -1136,6 +1153,7 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{}) d.Set("cpu", mvm.Summary.Config.NumCpu) d.Set("datastore", rootDatastore) d.Set("uuid", mvm.Summary.Config.Uuid) + d.Set("annotation", mvm.Summary.Config.Annotation) return nil } @@ -1776,6 +1794,7 @@ func (vm *virtualMachine) setupVirtualMachine(c *govmomi.Client) error { Flags: &types.VirtualMachineFlagInfo{ DiskUuidEnabled: &vm.enableDiskUUID, }, + Annotation: vm.annotation, } if vm.template == "" { configSpec.GuestId = "otherLinux64Guest" diff --git a/vsphere/resource_vsphere_virtual_machine_test.go b/vsphere/resource_vsphere_virtual_machine_test.go index 8f9ef96ae..737f7332b 100644 --- a/vsphere/resource_vsphere_virtual_machine_test.go +++ b/vsphere/resource_vsphere_virtual_machine_test.go @@ -1502,6 +1502,42 @@ func createAndAttachDisk(t *testing.T, vmName string, size int, datastore string } } +const testAccCheckVSphereVirtualMachineConfig_annotation = ` +resource "vsphere_virtual_machine" "car" { + name = "terraform-test-annotation" + annotation = "bar" +` + +func TestAccVSphereVirtualMachine_annotation(t *testing.T) { + + var vm virtualMachine + data := setupTemplateFuncDHCPData() + config := testAccCheckVSphereVirtualMachineConfig_annotation + data.parseDHCPTemplateConfigWithTemplate(testAccCheckVSphereTemplate_dhcp) + vmName := "vsphere_virtual_machine.car" + res := "terraform-test-annotation" + + test_exists, test_name, test_cpu, test_uuid, test_mem, test_num_disk, test_num_of_nic, test_nic_label := + TestFuncData{vm: vm, label: data.label, vmName: vmName, vmResource: res}.testCheckFuncBasic() + + log.Printf("[DEBUG] template= %s", testAccCheckVSphereVirtualMachineConfig_annotation+testAccCheckVSphereTemplate_dhcp) + log.Printf("[DEBUG] config= %s", config) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVSphereVirtualMachineDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + Check: resource.ComposeTestCheckFunc( + test_exists, test_name, test_cpu, test_uuid, test_mem, test_num_disk, test_num_of_nic, test_nic_label, + resource.TestCheckResourceAttr(vmName, "annotation", "bar"), + ), + }, + }, + }) +} + func vmCleanup(dc *object.Datacenter, ds *object.Datastore, vmName string) error { client := testAccProvider.Meta().(*govmomi.Client) fileManager := object.NewFileManager(client.Client) diff --git a/website/docs/r/virtual_machine.html.markdown b/website/docs/r/virtual_machine.html.markdown index f2885b7e5..5ba3f2d6a 100644 --- a/website/docs/r/virtual_machine.html.markdown +++ b/website/docs/r/virtual_machine.html.markdown @@ -82,6 +82,7 @@ The following arguments are supported: * `enable_disk_uuid` - (Optional) This option causes the vm to mount disks by uuid on the guest OS. * `custom_configuration_parameters` - (Optional) Map of values that is set as virtual machine custom configurations. * `skip_customization` - (Optional) skip virtual machine customization (useful if OS is not in the guest OS support matrix of VMware like "other3xLinux64Guest"). +* `annotation` - (Optional) Edit the annotation notes field The `network_interface` block supports: