Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

🚧 feat: add vapp properties #299

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .web-docs/components/builder/vsphere-iso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,8 @@ boot time.

- `destroy` (bool) - Specifies whether to destroy the virtual machine after the build is complete.

- `vapp` (vAppConfig) - Set the vApp properties for a virtual machine.

<!-- End of code generated from the comments of the CreateConfig struct in builder/vsphere/iso/step_create.go; -->


Expand Down
25 changes: 13 additions & 12 deletions builder/vsphere/driver/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,19 @@ type NIC struct {
}

type CreateConfig struct {
Annotation string
Name string
Folder string
Cluster string
Host string
ResourcePool string
Datastore string
GuestOS string // example: otherGuest
NICs []NIC
USBController []string
Version uint // example: 10
StorageConfig StorageConfig
Annotation string
Name string
Folder string
Cluster string
Host string
ResourcePool string
Datastore string
GuestOS string // example: otherGuest
NICs []NIC
USBController []string
Version uint // example: 10
StorageConfig StorageConfig
VAppProperties map[string]string
}

func (d *VCenterDriver) NewVM(ref *types.ManagedObjectReference) VirtualMachine {
Expand Down
2 changes: 2 additions & 0 deletions builder/vsphere/iso/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion builder/vsphere/iso/step_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MPL-2.0

//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type NIC,CreateConfig
//go:generate packer-sdc mapstructure-to-hcl2 -type NIC,CreateConfig,vAppConfig

package iso

Expand All @@ -19,6 +19,17 @@ import (
"github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/driver"
)

type vAppConfig struct {
tenthirtyam marked this conversation as resolved.
Show resolved Hide resolved
// Set values for the available vApp Properties to supply configuration parameters to a virtual machine cloned from
// a template that came from an imported OVF or OVA file.
//
// -> **Note:** The only supported usage path for vApp properties is for existing user-configurable keys.
// These generally come from an existing template that was created from an imported OVF or OVA file.
// You cannot set values for vApp properties on virtual machines created from scratch,
// virtual machines lacking a vApp configuration, or on property keys that do not exist.
Properties map[string]string `mapstructure:"properties"`
}

// Defines a Network Adapter
// If no adapter is defined, network tasks (communicators, most provisioners) won't work, so it's advised to define one.
//
Expand Down Expand Up @@ -99,6 +110,8 @@ type CreateConfig struct {
Notes string `mapstructure:"notes"`
// Specifies whether to destroy the virtual machine after the build is complete.
Destroy bool `mapstructure:"destroy"`
// Set the vApp properties for a virtual machine.
VAppConfig vAppConfig `mapstructure:"vapp"`
}

func (c *CreateConfig) Prepare() []error {
Expand Down Expand Up @@ -185,6 +198,7 @@ func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multiste
}

vm, err := d.CreateVM(&driver.CreateConfig{
VAppProperties: s.Config.VAppConfig.Properties,
StorageConfig: driver.StorageConfig{
DiskControllerType: s.Config.StorageConfig.DiskControllerType,
Storage: disks,
Expand Down
25 changes: 25 additions & 0 deletions builder/vsphere/iso/step_create.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions builder/vsphere/iso/step_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ func driverCreateConfig(config *CreateConfig, location *common.LocationConfig) *
}

return &driver.CreateConfig{
VAppProperties: config.VAppConfig.Properties,
StorageConfig: driver.StorageConfig{
DiskControllerType: config.StorageConfig.DiskControllerType,
Storage: disks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@

- `destroy` (bool) - Specifies whether to destroy the virtual machine after the build is complete.

- `vapp` (vAppConfig) - Set the vApp properties for a virtual machine.

<!-- End of code generated from the comments of the CreateConfig struct in builder/vsphere/iso/step_create.go; -->
11 changes: 11 additions & 0 deletions docs-partials/builder/vsphere/iso/vAppConfig-not-required.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Code generated from the comments of the vAppConfig struct in builder/vsphere/iso/step_create.go; DO NOT EDIT MANUALLY -->

- `properties` (map[string]string) - Set values for the available vApp Properties to supply configuration parameters to a virtual machine cloned from
tenthirtyam marked this conversation as resolved.
Show resolved Hide resolved
a template that came from an imported OVF or OVA file.

-> **Note:** The only supported usage path for vApp properties is for existing user-configurable keys.
These generally come from an existing template that was created from an imported OVF or OVA file.
You cannot set values for vApp properties on virtual machines created from scratch,
virtual machines lacking a vApp configuration, or on property keys that do not exist.

<!-- End of code generated from the comments of the vAppConfig struct in builder/vsphere/iso/step_create.go; -->