Skip to content

Commit

Permalink
virtual machine - add annotation argument
Browse files Browse the repository at this point in the history
  • Loading branch information
verdel committed Jul 25, 2017
1 parent 8653ce6 commit 8624dab
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
19 changes: 19 additions & 0 deletions vsphere/resource_vsphere_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type virtualMachine struct {
vcpu int32
memoryMb int64
memoryAllocation memoryAllocation
annotation string
template string
networkInterfaces []networkInterface
hardDisks []hardDisk
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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"
Expand Down
36 changes: 36 additions & 0 deletions vsphere/resource_vsphere_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 8624dab

Please sign in to comment.