hashicorp / packer-plugin-vsphere

Packer plugin for VMware vSphere Builder
https://www.packer.io/docs/builders/vsphere
Mozilla Public License 2.0
96 stars 91 forks source link

`vsphere-supervisor`: use a shorter default `source_name` #455

Open dilyar85 opened 1 month ago

dilyar85 commented 1 month ago

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request. If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

Currently, if the source_name config is not provided, the Supervisor builder will use packer-vsphere-supervisor-<random-suffix> as the default source name as documented in https://developer.hashicorp.com/packer/integrations/hashicorp/vsphere/latest/components/builder/vsphere-supervisor#source-vm-creation

This is causing issues for deploying Windows VMs as they require a shorter hostname.

Use Case(s)

Provide a default source name that satisfies the Windows hostname requirement of 1 to 15 characters long.

Potential configuration

Instead of using a prefix, generate a random 4-character long name if the source_name config is not specified. This name should be generic since it's used for creating all required source objects (e.g., VM, VMService, Secret, etc.).

Potential References

Windows hostname requirement: https://learn.microsoft.com/en-us/troubleshoot/windows-server/active-directory/naming-conventions-for-computer-domain-site-ou

Current prefix code: https://github.com/hashicorp/packer-plugin-vsphere/blob/main/builder/vsphere/supervisor/step_create_source.go#L26

tenthirtyam commented 2 days ago

Why not simply change this to:

const (
    DefaultSourceNamePrefix = "source"
)

Then the name would be 12 characters by default. e.g. source-12345

Also, limit it to 15 if provided.

if c.SourceName == "" {
    c.SourceName = fmt.Sprintf("%s-%s", DefaultSourceNamePrefix, randString(5))
}

if len(c.SourceName) > 15 {
        return fmt.Errorf("'source_name' must not exceed 15 characters (length: %d): %s", len(c.SourceName), c.SourceName)
}