hashicorp / packer-plugin-vsphere

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

feat: set template name #416

Closed tenthirtyam closed 4 months ago

tenthirtyam commented 5 months ago

Summary

Adds the ability to set the name of the of the template in the vsphere-template post-processor. If template_name is not provided, the name of the source virtual machine will be used.

Testing

General: PASS ✅

packer-plugin-vsphere1 on  feat/set-template-name [$!] via 🐹 v1.22.2 
➜ make generate
2024/04/27 21:02:44 Copying "docs" to ".docs/"
2024/04/27 21:02:44 Replacing @include '...' calls in .docs/
Compiling MDX docs in '.docs' to Markdown in '.web-docs'...

packer-plugin-vsphere1 on  feat/set-template-name [$!] via 🐹 v1.22.2 took 11.6s 
➜ make build

packer-plugin-vsphere1 on  feat/set-template-name [$!] via 🐹 v1.22.2 took 3.5s 
➜ make test
?       github.com/hashicorp/packer-plugin-vsphere      [no test files]
?       github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/common/testing       [no test files]
?       github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/examples/driver      [no test files]
?       github.com/hashicorp/packer-plugin-vsphere/version      [no test files]
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/clone        1.526s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/common       3.218s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/driver       5.048s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/iso  2.238s
ok      github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/supervisor   4.171s
ok      github.com/hashicorp/packer-plugin-vsphere/post-processor/vsphere       2.378s
ok      github.com/hashicorp/packer-plugin-vsphere/post-processor/vsphere-template      2.764s

End-to-End: ✅

No value for template_name:

build {
  sources = ["source.vsphere-iso.linux-photon"]

  post-processors {
    post-processor "vsphere-template"{
        host                = var.vsphere_endpoint
        username            = var.vsphere_username
        password            = var.vsphere_password
        insecure            = var.vsphere_insecure_connection
        datacenter          = var.vsphere_datacenter
        folder              = var.vsphere_folder
    }
  }
}
==> vsphere-iso.linux-photon: Reattaching CD-ROM devices...
==> vsphere-iso.linux-photon: Adding SATA controller...
==> vsphere-iso.linux-photon: Adding CD-ROM devices...
==> vsphere-iso.linux-photon: Exporting to Open Virtualization Format (OVF)...
==> vsphere-iso.linux-photon: Downloading linux-photon-5.0-develop-disk-0.vmdk...
==> vsphere-iso.linux-photon: Exporting linux-photon-5.0-develop-disk-0.vmdk...
==> vsphere-iso.linux-photon: Writing OVF descriptor linux-photon-5.0-develop.ovf...
==> vsphere-iso.linux-photon: Creating SHA256 manifest linux-photon-5.0-develop.mf...
==> vsphere-iso.linux-photon: Completed export to Open Virtualization Format (OVF).
    vsphere-iso.linux-photon: Closing sessions ....
==> vsphere-iso.linux-photon: Running post-processor:  (type vsphere-template)
    vsphere-iso.linux-photon (vsphere-template): Pausing momentarily to prepare for the next step...
    vsphere-iso.linux-photon (vsphere-template): Choosing datacenter...
    vsphere-iso.linux-photon (vsphere-template): Creating or checking destination folder...
    vsphere-iso.linux-photon (vsphere-template): Registering virtual machine as a template: linux-photon-5.0-develop
Build 'vsphere-iso.linux-photon' finished after 2 minutes 36 seconds.

==> Wait completed after 2 minutes 36 seconds
==> Builds finished. The artifacts of successful builds are:
--> vsphere-iso.linux-photon: linux-photon-5.0-develop

Value set for template_name to i-am-a-template:

build {
  sources = ["source.vsphere-iso.linux-photon"]

  post-processors {
    post-processor "vsphere-template"{
        template_name       = "i-am-a-template"        # <<<< --- template name
        host                = var.vsphere_endpoint
        username            = var.vsphere_username
        password            = var.vsphere_password
        insecure            = var.vsphere_insecure_connection
        datacenter          = var.vsphere_datacenter
        folder              = var.vsphere_folder
    }
  }
}
==> vsphere-iso.linux-photon: Reattaching CD-ROM devices...
==> vsphere-iso.linux-photon: Adding SATA controller...
==> vsphere-iso.linux-photon: Adding CD-ROM devices...
==> vsphere-iso.linux-photon: Exporting to Open Virtualization Format (OVF)...
==> vsphere-iso.linux-photon: Downloading linux-photon-5.0-develop-disk-0.vmdk...
==> vsphere-iso.linux-photon: Exporting linux-photon-5.0-develop-disk-0.vmdk...
==> vsphere-iso.linux-photon: Writing OVF descriptor linux-photon-5.0-develop.ovf...
==> vsphere-iso.linux-photon: Creating SHA256 manifest linux-photon-5.0-develop.mf...
==> vsphere-iso.linux-photon: Completed export to Open Virtualization Format (OVF).
    vsphere-iso.linux-photon: Closing sessions ....
==> vsphere-iso.linux-photon: Running post-processor:  (type vsphere-template)
    vsphere-iso.linux-photon (vsphere-template): Pausing momentarily to prepare for the next step...
    vsphere-iso.linux-photon (vsphere-template): Choosing datacenter...
    vsphere-iso.linux-photon (vsphere-template): Creating or checking destination folder...
    vsphere-iso.linux-photon (vsphere-template): Registering virtual machine as a template: i-am-a-template
    # ^^^ template name ^^^ 
Build 'vsphere-iso.linux-photon' finished after 2 minutes 35 seconds.

==> Wait completed after 2 minutes 35 seconds

==> Builds finished. The artifacts of successful builds are:
--> vsphere-iso.linux-photon: linux-photon-5.0-develop

[!NOTE]

When using the template_name option the virtual machine will be registered with the new name; however, please note that the directory path and files will still retain the prior name. Renaming the directory and files is beyond the scope of this pull request.

Reference

Closes #397