Skip to content

Commit

Permalink
Add tools_upgrade_policy argument to the vsphere_virtual_machine
Browse files Browse the repository at this point in the history
…resource (#1506)

* Add `tools_upgrade_policy` argument

Addresses #1297
- Add `tools_upgrade_policy` argument to the `vsphere_virtual_machine` resource to set the upgrade policy for VMware Tools. One of `manual` or `upgradeAtPowerCycle`. Default: `manual`
- Updates the `vsphere_virtual_machine` resource docs to include the tools_upgrade_policy` argument.

Signed-off-by: Ryan Johnson <[email protected]>
  • Loading branch information
Ryan Johnson authored Feb 25, 2022
1 parent 2cd343c commit de94b45
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 15 additions & 1 deletion vsphere/virtual_machine_config_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ var virtualMachineSwapPlacementAllowedValues = []string{
string(types.VirtualMachineConfigInfoSwapPlacementTypeHostLocal),
}

var virtualMachineUpgradePolicyAllowedValues = []string{
string(types.UpgradePolicyManual),
string(types.UpgradePolicyUpgradeAtPowerCycle),
}

var virtualMachineFirmwareAllowedValues = []string{
string(types.GuestOsDescriptorFirmwareTypeBios),
string(types.GuestOsDescriptorFirmwareTypeEfi),
Expand All @@ -50,7 +55,7 @@ var virtualMachineLatencySensitivityAllowedValues = []string{
string(types.LatencySensitivitySensitivityLevelHigh),
}

// getWithRestart fetches the resoruce data specified at key. If the value has
// getWithRestart fetches the resource data specified at key. If the value has
// changed, a reboot is flagged in the virtual machine by setting
// reboot_required to true.
func getWithRestart(d *schema.ResourceData, key string) interface{} {
Expand Down Expand Up @@ -145,6 +150,13 @@ func schemaVirtualMachineConfigSpec() map[string]*schema.Schema {
Optional: true,
Description: "Enable guest clock synchronization with the host. On vSphere 7.0 U1 and above, with only this setting the clock is synchronized on startup and resume. Requires VMware Tools to be installed.",
},
"tools_upgrade_policy": {
Type: schema.TypeString,
Optional: true,
Default: string(types.UpgradePolicyManual),
Description: "Set the upgrade policy for VMware Tools. Can be one of `manual` or `upgradeAtPowerCycle`.",
ValidateFunc: validation.StringInSlice(virtualMachineUpgradePolicyAllowedValues, false),
},
"sync_time_with_host_periodically": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -414,6 +426,7 @@ func flattenVirtualMachineFlagInfo(d *schema.ResourceData, obj *types.VirtualMac
func expandToolsConfigInfo(d *schema.ResourceData, client *govmomi.Client) *types.ToolsConfigInfo {
obj := &types.ToolsConfigInfo{
SyncTimeWithHost: structure.GetBool(d, "sync_time_with_host"),
ToolsUpgradePolicy: getWithRestart(d, "tools_upgrade_policy").(string),
AfterPowerOn: getBoolWithRestart(d, "run_tools_scripts_after_power_on"),
AfterResume: getBoolWithRestart(d, "run_tools_scripts_after_resume"),
BeforeGuestStandby: getBoolWithRestart(d, "run_tools_scripts_before_guest_standby"),
Expand All @@ -433,6 +446,7 @@ func expandToolsConfigInfo(d *schema.ResourceData, client *govmomi.Client) *type
// ToolsConfigInfo into the passed in ResourceData.
func flattenToolsConfigInfo(d *schema.ResourceData, obj *types.ToolsConfigInfo, client *govmomi.Client) error {
_ = d.Set("sync_time_with_host", obj.SyncTimeWithHost)
_ = d.Set("tools_upgrade_policy", obj.ToolsUpgradePolicy)
_ = d.Set("run_tools_scripts_after_power_on", obj.AfterPowerOn)
_ = d.Set("run_tools_scripts_after_resume", obj.AfterResume)
_ = d.Set("run_tools_scripts_before_guest_standby", obj.BeforeGuestStandby)
Expand Down
5 changes: 5 additions & 0 deletions website/docs/r/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,11 @@ The following options control boot settings on a virtual machine:

The following options control VMware Tools settings on the virtual machine:

* `tools_upgrade_policy` - (Optional) Enable automatic upgrade of the VMware Tools
version when the virtual machine is rebooted. If necessary, VMware Tools is upgraded
to the latest version supported by the host on which the virtual machine is running.
Requires VMware tools to be installed. One of `manual` or `upgradeAtPowerCycle`. Default: `manual`.

* `sync_time_with_host` - (Optional) Enable the guest operating system to synchronization its clock with the host when the virtual machine is powered on or resumed. Requires vSphere 7.0 Update 1 and later. Requires VMware Tools to be installed. Default: `false`.

* `sync_time_with_host_periodically` - (Optional) Enable the guest operating system to periodically synchronize its clock with the host. Requires vSphere 7.0 Update 1 and later. On previous versions, setting `sync_time_with_host` is will enable periodic synchronization. Requires VMware Tools to be installed. Default: `false`.
Expand Down

0 comments on commit de94b45

Please sign in to comment.