Skip to content

Conversation

@tenthirtyam
Copy link
Collaborator

@tenthirtyam tenthirtyam commented Sep 15, 2025

Description

Adds an override (bool) option to the vsphere-template post-processor, allowing the overwrite of an existing template if set to true.

packer-plugin-vsphere on  feat/add-override-option [$?] via 🐹 v1.23.11 took 13.3s 
➜ go test -v ./post-processor/vsphere-template/
=== RUN   TestConfigure_Valid
--- PASS: TestConfigure_Valid (0.00s)
=== RUN   TestConfigure_ReregisterVM_Default
--- PASS: TestConfigure_ReregisterVM_Default (0.00s)
=== RUN   TestConfigure_Override
=== RUN   TestConfigure_Override/default
=== RUN   TestConfigure_Override/true
=== RUN   TestConfigure_Override/false
--- PASS: TestConfigure_Override (0.00s)
    --- PASS: TestConfigure_Override/default (0.00s)
    --- PASS: TestConfigure_Override/true (0.00s)
    --- PASS: TestConfigure_Override/false (0.00s)
=== RUN   TestStepMarkAsTemplate_Override
=== RUN   TestStepMarkAsTemplate_Override/default
=== RUN   TestStepMarkAsTemplate_Override/enabled
=== RUN   TestStepMarkAsTemplate_Override/disabled
--- PASS: TestStepMarkAsTemplate_Override (0.00s)
    --- PASS: TestStepMarkAsTemplate_Override/default (0.00s)
    --- PASS: TestStepMarkAsTemplate_Override/enabled (0.00s)
    --- PASS: TestStepMarkAsTemplate_Override/disabled (0.00s)
=== RUN   TestStepMarkAsTemplate_TemplateName
=== RUN   TestStepMarkAsTemplate_TemplateName/Use_template_name_when_provided
=== RUN   TestStepMarkAsTemplate_TemplateName/Use_VM_name_when_template_name_is_empty
--- PASS: TestStepMarkAsTemplate_TemplateName (0.00s)
    --- PASS: TestStepMarkAsTemplate_TemplateName/Use_template_name_when_provided (0.00s)
    --- PASS: TestStepMarkAsTemplate_TemplateName/Use_VM_name_when_template_name_is_empty (0.00s)
PASS
ok      github.com/hashicorp/packer-plugin-vsphere/post-processor/vsphere-template      0.367s
packer {
  required_plugins {
    vsphere = {
      version = ">= 2.1.0"
      source  = "github.com/hashicorp/vsphere"
    }
  }
}

source "vsphere-iso" "example" {
  vcenter_server      = "vc01.example.com"
  insecure_connection = true
  username            = "[email protected]"
  password            = "VMw@re1!"
  datacenter          = "dc01"
  cluster             = "cl01"
  datastore           = "local-ssd01-esx01"
  folder              = "templates"
  vm_name             = "ubuntu-2404-lts"
  guest_os_type       = "ubuntu64Guest"
  communicator        = "ssh"
  ssh_username        = "ubuntu"
  ssh_password        = "ubuntu"
  ssh_timeout         = "30m"

  iso_urls     = ["https://releases.ubuntu.com/24.04/ubuntu-24.04.3-live-server-amd64.iso"]
  iso_checksum = "file:https://releases.ubuntu.com/24.04/SHA256SUMS"

  CPUs = 2
  RAM  = 4096

  storage {
    disk_size             = 32768
    disk_thin_provisioned = true
  }

  disk_controller_type = ["pvscsi"]

  network_adapters {
    network      = "VM Network"
    network_card = "vmxnet3"
  }

  boot_wait = "5s"
  boot_command = [
    "<esc><wait>",
    "c",
    "<wait>",
    "linux /casper/vmlinuz autoinstall ds=nocloud-net\\;s=http://{{.HTTPIP}}:{{.HTTPPort}}/ --- console=ttyS0",
    "<enter><wait>",
    "initrd /casper/initrd",
    "<enter><wait>",
    "boot<enter>"
  ]

  http_directory = "http"
}

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

  post-processor "vsphere-template" {
    host          = "vc01.example.com"
    insecure      = true
    username      = "[email protected]"
    password      = "VMw@re1!"
    datacenter    = "dc01"
    folder        = "templates"
    template_name = "ubuntu-2404-lts-test"
    override      = true
  }
}
==> vsphere-iso.example: Running post-processor:  (type vsphere-template)
==> vsphere-iso.example (vsphere-template): Pausing momentarily to prepare for the next step...
==> vsphere-iso.example (vsphere-template): Choosing datacenter...
==> vsphere-iso.example (vsphere-template): Creating or checking destination folder...
==> vsphere-iso.example (vsphere-template): Removing existing template 'ubuntu-2404-lts-test'...
==> vsphere-iso.example (vsphere-template): Successfully removed existing template 'ubuntu-2404-lts-test'.
==> vsphere-iso.example (vsphere-template): Registering virtual machine as a template: ubuntu-2404-lts-test
Build 'vsphere-iso.example' finished after 5 minutes 25 seconds.

If override = false (default):

==> vsphere-iso.example: Running post-processor:  (type vsphere-template)
==> vsphere-iso.example (vsphere-template): Pausing momentarily to prepare for the next step...
==> vsphere-iso.example (vsphere-template): Choosing datacenter...
==> vsphere-iso.example (vsphere-template): Creating or checking destination folder...
==> vsphere-iso.example (vsphere-template): template 'ubuntu-2404-lts-test' already exists. Set 'override = true' to replace existing templates
Build 'vsphere-iso.example' errored after 5 minutes 27 seconds: 2 error(s) occurred:

Resolved Issues

Closes #521

Rollback Plan

Revert commit.

Changes to Security Controls

None.

@tenthirtyam tenthirtyam added this to the v2.1.0 milestone Sep 15, 2025
@tenthirtyam tenthirtyam self-assigned this Sep 15, 2025
@tenthirtyam tenthirtyam force-pushed the feat/add-override-option branch from 9cd4105 to e34dc46 Compare September 15, 2025 01:33
@tenthirtyam tenthirtyam force-pushed the feat/add-override-option branch from e34dc46 to 7f6a279 Compare October 6, 2025 19:01
@tenthirtyam tenthirtyam force-pushed the feat/add-override-option branch 2 times, most recently from f29764c to 1cddfa0 Compare October 14, 2025 03:10
@tenthirtyam tenthirtyam changed the title [wip] feat: add override option feat: add override option Oct 14, 2025
@tenthirtyam tenthirtyam marked this pull request as ready for review October 14, 2025 03:14
@tenthirtyam tenthirtyam requested a review from a team as a code owner October 14, 2025 03:14
Copilot AI review requested due to automatic review settings October 14, 2025 03:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds an override boolean option to the vsphere-template post-processor, allowing users to overwrite existing templates when set to true. By default, the option is false, maintaining backward compatibility.

Key Changes

  • Added Override field to the Config struct with proper documentation and HCL2 specification
  • Implemented template existence checking and removal logic in the mark-as-template step
  • Added comprehensive test coverage for the new override functionality

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
post-processor/vsphere-template/post-processor.go Added Override field to Config struct
post-processor/vsphere-template/step_mark_as_template.go Implemented override logic with template existence checking and removal
post-processor/vsphere-template/step_mark_as_template_test.go Added comprehensive test coverage for override functionality
post-processor/vsphere-template/post-processor_test.go Added tests for override configuration
post-processor/vsphere-template/post-processor.hcl2spec.go Added HCL2 specification for override field
docs-partials/post-processor/vsphere-template/Config-not-required.mdx Updated documentation with override option
.web-docs/components/post-processor/vsphere-template/README.md Updated web documentation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@tenthirtyam tenthirtyam force-pushed the feat/add-override-option branch from 1cddfa0 to 0cab817 Compare October 14, 2025 03:16
@tenthirtyam tenthirtyam requested a review from Copilot October 14, 2025 03:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Adds an `override` (bool) option to the `vsphere-template` post-processor, allowing the overwrite of an existing template if set to `true`.

Signed-off-by: Ryan Johnson <[email protected]>
@tenthirtyam tenthirtyam force-pushed the feat/add-override-option branch from 0cab817 to 495050b Compare October 14, 2025 03:21
@tenthirtyam tenthirtyam requested a review from Copilot October 14, 2025 03:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@kp2099 kp2099 merged commit ae1442d into main Oct 16, 2025
14 checks passed
@kp2099 kp2099 deleted the feat/add-override-option branch October 16, 2025 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vsphere-template: add override option

2 participants