Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

enhance: Add extra_config_reboot_required to r/virtual_machine #1603

Merged
merged 3 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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