Skip to content

Commit

Permalink
feat: Add extra_config_reboot_required to r/virtual_machine
Browse files Browse the repository at this point in the history
Adds an optional `extra_config_reboot_required` argument to `r/virtual_machine. This argument allows you to configure if a virtual machine reboot is enforced when `extra_config` is changed.
  • Loading branch information
Ryan Johnson authored Jul 15, 2022
2 parents 395aa5c + 651d04a commit b0e650a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions vsphere/resource_vsphere_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
})
}
Expand Down Expand Up @@ -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}"
Expand Down
14 changes: 13 additions & 1 deletion vsphere/virtual_machine_config_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "Allow the virtual machine to be rebooted when a change to `extra_config` occurs.",
},
"replace_trigger": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -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 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
}
_ = 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.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b0e650a

Please # to comment.