From 349e024c0d84a619189a6d31f156d962c1311165 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Mon, 30 Sep 2024 10:57:28 -0400 Subject: [PATCH] fix: limit source vm to 15 char - Updates `DefaultSourceNamePrefix` to "source". - Limits the name of the source virtual machine to 15 characters to support Windows. This was causing issues for deploying Windows VMs as they require a shorter hostname. #455 Signed-off-by: Ryan Johnson --- .../components/builder/vsphere-supervisor/README.md | 2 +- builder/vsphere/supervisor/step_create_source.go | 9 ++++++--- .../supervisor/CreateSourceConfig-not-required.mdx | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.web-docs/components/builder/vsphere-supervisor/README.md b/.web-docs/components/builder/vsphere-supervisor/README.md index 0611211d..f0844f21 100644 --- a/.web-docs/components/builder/vsphere-supervisor/README.md +++ b/.web-docs/components/builder/vsphere-supervisor/README.md @@ -171,7 +171,7 @@ items are listed below as well as the _optional_ configurations. - `image_name` (string) - Name of the source virtual machine (VM) image. If it is specified, the image with the name will be used for the source VM, otherwise the image name from imported image will be used. -- `source_name` (string) - Name of the source VM. Defaults to `packer-vsphere-supervisor-`. +- `source_name` (string) - Name of the source VM. Limited to 15 characters. Defaults to `source-`. - `network_type` (string) - Name of the network type to attach to the source VM's network interface. Defaults to empty. diff --git a/builder/vsphere/supervisor/step_create_source.go b/builder/vsphere/supervisor/step_create_source.go index 5bb483e1..4e559849 100644 --- a/builder/vsphere/supervisor/step_create_source.go +++ b/builder/vsphere/supervisor/step_create_source.go @@ -23,7 +23,7 @@ import ( ) const ( - DefaultSourceNamePrefix = "packer-vsphere-supervisor" + DefaultSourceNamePrefix = "source" VMSelectorLabelKey = DefaultSourceNamePrefix + "-selector" StateKeySourceName = "source_name" @@ -42,11 +42,10 @@ type CreateSourceConfig struct { ClassName string `mapstructure:"class_name" required:"true"` // Name of the storage class that configures storage-related attributes. StorageClass string `mapstructure:"storage_class" required:"true"` - // Name of the source virtual machine (VM) image. If it is specified, the image with the name will be used for the // source VM, otherwise the image name from imported image will be used. ImageName string `mapstructure:"image_name"` - // Name of the source VM. Defaults to `packer-vsphere-supervisor-`. + // Name of the source VM. Limited to 15 characters. Defaults to `source-`. SourceName string `mapstructure:"source_name"` // Name of the network type to attach to the source VM's network interface. Defaults to empty. NetworkType string `mapstructure:"network_type"` @@ -86,6 +85,10 @@ func (c *CreateSourceConfig) Prepare() []error { c.SourceName = fmt.Sprintf("%s-%s", DefaultSourceNamePrefix, rand.String(5)) } + if len(c.SourceName) > 15 { + errs = append(errs, fmt.Errorf("'source_name' must not exceed 15 characters (length: %d): %s", len(c.SourceName), c.SourceName)) + } + return errs } diff --git a/docs-partials/builder/vsphere/supervisor/CreateSourceConfig-not-required.mdx b/docs-partials/builder/vsphere/supervisor/CreateSourceConfig-not-required.mdx index 04e18bfc..4846d7a0 100644 --- a/docs-partials/builder/vsphere/supervisor/CreateSourceConfig-not-required.mdx +++ b/docs-partials/builder/vsphere/supervisor/CreateSourceConfig-not-required.mdx @@ -3,7 +3,7 @@ - `image_name` (string) - Name of the source virtual machine (VM) image. If it is specified, the image with the name will be used for the source VM, otherwise the image name from imported image will be used. -- `source_name` (string) - Name of the source VM. Defaults to `packer-vsphere-supervisor-`. +- `source_name` (string) - Name of the source VM. Limited to 15 characters. Defaults to `source-`. - `network_type` (string) - Name of the network type to attach to the source VM's network interface. Defaults to empty.