From daeb28cc4e7261152fc13f77a6ef62e1e10df6a4 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 25 Feb 2022 11:34:17 +0000 Subject: [PATCH 1/3] add extra_config_reboot_required --- vsphere/virtual_machine_config_structure.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/vsphere/virtual_machine_config_structure.go b/vsphere/virtual_machine_config_structure.go index 261547639..ebd4a304b 100644 --- a/vsphere/virtual_machine_config_structure.go +++ b/vsphere/virtual_machine_config_structure.go @@ -300,6 +300,12 @@ func schemaVirtualMachineConfigSpec() map[string]*schema.Schema { Description: "Extra configuration data for this virtual machine. Can be used to supply advanced parameters not normally in configuration, such as instance metadata, or configuration data for OVF images.", Elem: &schema.Schema{Type: schema.TypeString}, }, + "extra_config_reboot_required": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "Configure if a change of extra_config will trigger a reboot", + }, "replace_trigger": { Type: schema.TypeString, Optional: true, @@ -579,7 +585,13 @@ func expandExtraConfig(d *schema.ResourceData) []types.BaseOptionValue { // While there's a possibility that modification of some settings in // extraConfig may not require a restart, there's no real way for us to // know, hence we just default to requiring a reboot here. - _ = d.Set("reboot_required", true) + rebootRequired := true + // Check if the user has specified that no reboot is required + _rebootRequired, ok := d.Get("extra_config_reboot_required").(bool) + if ok { + rebootRequired = _rebootRequired + } + _ = d.Set("reboot_required", rebootRequired) } else { // There's no change here, so we might as well just return a nil set, which // is a no-op for modification of extraConfig. From 569824c9d7537c736eaeec3998c069d7ad373d0c Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 25 Feb 2022 11:46:11 +0000 Subject: [PATCH 2/3] add tests --- vsphere/resource_vsphere_virtual_machine_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/vsphere/resource_vsphere_virtual_machine_test.go b/vsphere/resource_vsphere_virtual_machine_test.go index 62413d9ab..2a8100a12 100644 --- a/vsphere/resource_vsphere_virtual_machine_test.go +++ b/vsphere/resource_vsphere_virtual_machine_test.go @@ -1027,6 +1027,14 @@ func TestAccResourceVSphereVirtualMachine_extraConfig(t *testing.T) { testAccResourceVSphereVirtualMachineCheckExtraConfig("foo", "bar"), ), }, + { + Config: testAccResourceVSphereVirtualMachineConfigExtraConfig("foo", "baz"), + Check: resource.ComposeTestCheckFunc( + testAccResourceVSphereVirtualMachineCheckExists(true), + resource.TestCheckResourceAttr("vsphere_virtual_machine.vm", "reboot_required", "false"), + testAccResourceVSphereVirtualMachineCheckExtraConfig("foo", "baz"), + ), + }, }, }) } @@ -4544,6 +4552,7 @@ resource "vsphere_virtual_machine" "vm" { extra_config = { %s = "%s" } + extra_config_reboot_required = false network_interface { network_id = "${data.vsphere_network.network1.id}" From 651d04a53ef8cc70059dea0991c493a166af86cd Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 25 Feb 2022 20:12:54 +0100 Subject: [PATCH 3/3] add docs and reword description --- vsphere/virtual_machine_config_structure.go | 4 ++-- website/docs/r/virtual_machine.html.markdown | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/vsphere/virtual_machine_config_structure.go b/vsphere/virtual_machine_config_structure.go index ebd4a304b..caeb5a2fa 100644 --- a/vsphere/virtual_machine_config_structure.go +++ b/vsphere/virtual_machine_config_structure.go @@ -304,7 +304,7 @@ func schemaVirtualMachineConfigSpec() map[string]*schema.Schema { Type: schema.TypeBool, Optional: true, Default: true, - Description: "Configure if a change of extra_config will trigger a reboot", + Description: "Allow the virtual machine to be rebooted when a change to `extra_config` occurs.", }, "replace_trigger": { Type: schema.TypeString, @@ -586,7 +586,7 @@ func expandExtraConfig(d *schema.ResourceData) []types.BaseOptionValue { // extraConfig may not require a restart, there's no real way for us to // know, hence we just default to requiring a reboot here. rebootRequired := true - // Check if the user has specified that no reboot is required + // Check for an override to the default reboot when changes are made to the extraConfig. _rebootRequired, ok := d.Get("extra_config_reboot_required").(bool) if ok { rebootRequired = _rebootRequired diff --git a/website/docs/r/virtual_machine.html.markdown b/website/docs/r/virtual_machine.html.markdown index 2d9fd37b8..f65c70e4d 100644 --- a/website/docs/r/virtual_machine.html.markdown +++ b/website/docs/r/virtual_machine.html.markdown @@ -616,6 +616,8 @@ The following options are general virtual machine and provider workflow options: * `clone` - (Optional) When specified, the virtual machine will be created as a clone of a specified template. Optional customization options can be submitted for the resource. See [creating a virtual machine from a template](#creating-a-virtual-machine-from-a-template) for more information. +* `extra_config_reboot_required` - (Optional) Allow the virtual machine to be rebooted when a change to `extra_config` occurs. Default: `true`. + * `custom_attributes` - (Optional) Map of custom attribute ids to attribute value strings to set for virtual machine. Please refer to the [`vsphere_custom_attributes`][docs-setting-custom-attributes] resource for more information on setting custom attributes. [docs-setting-custom-attributes]: /docs/providers/vsphere/r/custom_attribute.html#using-custom-attributes-in-a-supported-resource