Skip to content
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
33 changes: 29 additions & 4 deletions .web-docs/components/builder/vsphere-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,39 @@ JSON Example:

<!-- Code generated from the comments of the ConfigParamsConfig struct in builder/vsphere/common/step_config_params.go; DO NOT EDIT MANUALLY -->

- `configuration_parameters` (map[string]string) - configuration_parameters is a direct passthrough to the vSphere API's
[VirtualMachineConfigSpec](https://developer.broadcom.com/xapis/virtual-infrastructure-json-api/8.0.2.0/data-structures/VirtualMachineConfigSpec/)
- `configuration_parameters` (map[string]string) - A map of key-value pairs to sent to the [`extraConfig`](https://dp-downloads.broadcom.com/api-content/apis/API_VWSA_001/8.0U3/html/ReferenceGuides/vim.vm.ConfigSpec.html#extraConfig).
in the vSphere API's `VirtualMachineConfigSpec`.

HCL Example:

```hcl
configuration_parameters = {
"disk.EnableUUID" = "TRUE"
"svga.autodetect" = "TRUE"
"log.keepOld" = "15"
}
```

JSON Example:

```json
"configuration_parameters": {
"disk.EnableUUID": "TRUE",
"svga.autodetect": "TRUE",
"log.keepOld": "15"
}
```

~> **Note:** Configuration keys that would conflict with parameters that
are explicitly configurable through other fields in the `ConfigSpec`` object
are silently ignored. Refer to the [`VirtualMachineConfigSpec`](https://dp-downloads.broadcom.com/api-content/apis/API_VWSA_001/8.0U3/html/ReferenceGuides/vim.vm.ConfigSpec.html)
in the vSphere API documentation.

- `tools_sync_time` (bool) - Enable time synchronization with the ESXi host where the virtual machine
is running. Defaults to `false`.

- `tools_upgrade_policy` (bool) - Automatically check for and upgrade VMware Tools after a virtual
machine power cycle. Defaults to `false`.
- `tools_upgrade_policy` (bool) - Automatically check for and upgrade VMware Tools after a virtual machine
power cycle. Defaults to `false`.

<!-- End of code generated from the comments of the ConfigParamsConfig struct in builder/vsphere/common/step_config_params.go; -->

Expand Down
33 changes: 29 additions & 4 deletions .web-docs/components/builder/vsphere-iso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1396,14 +1396,39 @@ JSON Example:

<!-- Code generated from the comments of the ConfigParamsConfig struct in builder/vsphere/common/step_config_params.go; DO NOT EDIT MANUALLY -->

- `configuration_parameters` (map[string]string) - configuration_parameters is a direct passthrough to the vSphere API's
[VirtualMachineConfigSpec](https://developer.broadcom.com/xapis/virtual-infrastructure-json-api/8.0.2.0/data-structures/VirtualMachineConfigSpec/)
- `configuration_parameters` (map[string]string) - A map of key-value pairs to sent to the [`extraConfig`](https://dp-downloads.broadcom.com/api-content/apis/API_VWSA_001/8.0U3/html/ReferenceGuides/vim.vm.ConfigSpec.html#extraConfig).
in the vSphere API's `VirtualMachineConfigSpec`.

HCL Example:

```hcl
configuration_parameters = {
"disk.EnableUUID" = "TRUE"
"svga.autodetect" = "TRUE"
"log.keepOld" = "15"
}
```

JSON Example:

```json
"configuration_parameters": {
"disk.EnableUUID": "TRUE",
"svga.autodetect": "TRUE",
"log.keepOld": "15"
}
```

~> **Note:** Configuration keys that would conflict with parameters that
are explicitly configurable through other fields in the `ConfigSpec`` object
are silently ignored. Refer to the [`VirtualMachineConfigSpec`](https://dp-downloads.broadcom.com/api-content/apis/API_VWSA_001/8.0U3/html/ReferenceGuides/vim.vm.ConfigSpec.html)
in the vSphere API documentation.

- `tools_sync_time` (bool) - Enable time synchronization with the ESXi host where the virtual machine
is running. Defaults to `false`.

- `tools_upgrade_policy` (bool) - Automatically check for and upgrade VMware Tools after a virtual
machine power cycle. Defaults to `false`.
- `tools_upgrade_policy` (bool) - Automatically check for and upgrade VMware Tools after a virtual machine
power cycle. Defaults to `false`.

<!-- End of code generated from the comments of the ConfigParamsConfig struct in builder/vsphere/common/step_config_params.go; -->

Expand Down
40 changes: 36 additions & 4 deletions builder/vsphere/common/step_config_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package common
import (
"context"
"fmt"
"log"

"github.com/vmware/govmomi/vim25/types"

Expand All @@ -18,14 +19,39 @@ import (
)

type ConfigParamsConfig struct {
// configuration_parameters is a direct passthrough to the vSphere API's
// [VirtualMachineConfigSpec](https://developer.broadcom.com/xapis/virtual-infrastructure-json-api/8.0.2.0/data-structures/VirtualMachineConfigSpec/)
// A map of key-value pairs to sent to the [`extraConfig`](https://dp-downloads.broadcom.com/api-content/apis/API_VWSA_001/8.0U3/html/ReferenceGuides/vim.vm.ConfigSpec.html#extraConfig).
// in the vSphere API's `VirtualMachineConfigSpec`.
//
// HCL Example:
//
// ```hcl
// configuration_parameters = {
// "disk.EnableUUID" = "TRUE"
// "svga.autodetect" = "TRUE"
// "log.keepOld" = "15"
// }
// ```
//
// JSON Example:
//
// ```json
// "configuration_parameters": {
// "disk.EnableUUID": "TRUE",
// "svga.autodetect": "TRUE",
// "log.keepOld": "15"
// }
// ```
//
// ~> **Note:** Configuration keys that would conflict with parameters that
// are explicitly configurable through other fields in the `ConfigSpec`` object
// are silently ignored. Refer to the [`VirtualMachineConfigSpec`](https://dp-downloads.broadcom.com/api-content/apis/API_VWSA_001/8.0U3/html/ReferenceGuides/vim.vm.ConfigSpec.html)
// in the vSphere API documentation.
ConfigParams map[string]string `mapstructure:"configuration_parameters"`
// Enable time synchronization with the ESXi host where the virtual machine
// is running. Defaults to `false`.
ToolsSyncTime bool `mapstructure:"tools_sync_time"`
// Automatically check for and upgrade VMware Tools after a virtual
// machine power cycle. Defaults to `false`.
// Automatically check for and upgrade VMware Tools after a virtual machine
// power cycle. Defaults to `false`.
ToolsUpgradePolicy bool `mapstructure:"tools_upgrade_policy"`
}

Expand Down Expand Up @@ -56,6 +82,12 @@ func (s *StepConfigParams) Run(_ context.Context, state multistep.StateBag) mult
}

ui.Say("Adding configuration parameters...")

// Iterate over the map and log each key-value pair.
for key, value := range configParams {
log.Printf("[INFO] Adding: %s = %v", key, value)
}

if err := vm.AddConfigParams(configParams, info); err != nil {
state.Put("error", fmt.Errorf("error adding configuration parameters: %v", err))
return multistep.ActionHalt
Expand Down
42 changes: 37 additions & 5 deletions builder/vsphere/driver/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1285,11 +1285,11 @@ func (vm *VirtualMachineDriver) AddConfigParams(params map[string]string, info *

var ov []types.BaseOptionValue
for k, v := range params {
o := types.OptionValue{
o := &types.OptionValue{
Key: k,
Value: v,
}
ov = append(ov, &o)
ov = append(ov, o)
}
confSpec.ExtraConfig = ov

Expand All @@ -1298,14 +1298,46 @@ func (vm *VirtualMachineDriver) AddConfigParams(params map[string]string, info *
if len(confSpec.ExtraConfig) > 0 || confSpec.Tools != nil {
task, err := vm.vm.Reconfigure(vm.driver.ctx, confSpec)
if err != nil {
return err
return fmt.Errorf("failed to start reconfiguration task: %w", err)
}

_, err = task.WaitForResult(vm.driver.ctx, nil)
return err
if err != nil {
return fmt.Errorf("reconfiguration task failed: %w", err)
}

log.Println("[INFO] Reconfiguration task completed successfully.")

// Retrieve the current configuration.
var moVM mo.VirtualMachine
err = vm.vm.Properties(vm.driver.ctx, vm.vm.Reference(), []string{"config.extraConfig"}, &moVM)
if err != nil {
return fmt.Errorf("failed to retrieve current configuration: %w", err)
}

// Check for ignored parameters
ignoredParams := []string{}
for k, v := range params {
found := false
for _, option := range moVM.Config.ExtraConfig {
if optVal, ok := option.(*types.OptionValue); ok && optVal.Key == k && optVal.Value == v {
found = true
break
}
}
if !found {
ignoredParams = append(ignoredParams, fmt.Sprintf("%s = %v", k, v))
}
}

if len(ignoredParams) > 0 {
log.Printf("[INFO] Ignored the following parameters: [%s]", strings.Join(ignoredParams, " , "))
log.Printf("[INFO] Some configuration keys were ignored due to conflicts with other fields in the ConfigSpec. Refer to VirtualMachineConfigSpec in the vSphere API documentation.")
}
return nil
}

return nil
return fmt.Errorf("no changes to apply")
}

func (vm *VirtualMachineDriver) AddFlag(ctx context.Context, flagSpec *types.VirtualMachineFlagInfo) error {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
<!-- Code generated from the comments of the ConfigParamsConfig struct in builder/vsphere/common/step_config_params.go; DO NOT EDIT MANUALLY -->

- `configuration_parameters` (map[string]string) - configuration_parameters is a direct passthrough to the vSphere API's
[VirtualMachineConfigSpec](https://developer.broadcom.com/xapis/virtual-infrastructure-json-api/8.0.2.0/data-structures/VirtualMachineConfigSpec/)
- `configuration_parameters` (map[string]string) - A map of key-value pairs to sent to the [`extraConfig`](https://dp-downloads.broadcom.com/api-content/apis/API_VWSA_001/8.0U3/html/ReferenceGuides/vim.vm.ConfigSpec.html#extraConfig).
in the vSphere API's `VirtualMachineConfigSpec`.

HCL Example:

```hcl
configuration_parameters = {
"disk.EnableUUID" = "TRUE"
"svga.autodetect" = "TRUE"
"log.keepOld" = "15"
}
```

JSON Example:

```json
"configuration_parameters": {
"disk.EnableUUID": "TRUE",
"svga.autodetect": "TRUE",
"log.keepOld": "15"
}
```

~> **Note:** Configuration keys that would conflict with parameters that
are explicitly configurable through other fields in the `ConfigSpec`` object
are silently ignored. Refer to the [`VirtualMachineConfigSpec`](https://dp-downloads.broadcom.com/api-content/apis/API_VWSA_001/8.0U3/html/ReferenceGuides/vim.vm.ConfigSpec.html)
in the vSphere API documentation.

- `tools_sync_time` (bool) - Enable time synchronization with the ESXi host where the virtual machine
is running. Defaults to `false`.

- `tools_upgrade_policy` (bool) - Automatically check for and upgrade VMware Tools after a virtual
machine power cycle. Defaults to `false`.
- `tools_upgrade_policy` (bool) - Automatically check for and upgrade VMware Tools after a virtual machine
power cycle. Defaults to `false`.

<!-- End of code generated from the comments of the ConfigParamsConfig struct in builder/vsphere/common/step_config_params.go; -->