Skip to content

Commit

Permalink
Allow deleting VM after vsphere-iso completion (#204)
Browse files Browse the repository at this point in the history
* Allow deleting VM after vsphere-iso completion

* Move destroy configuration to CreateConfig configuration
  • Loading branch information
paleloser authored Aug 12, 2022
1 parent 9fe830b commit ff5bd54
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
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.

5 changes: 5 additions & 0 deletions builder/vsphere/iso/step_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type CreateConfig struct {
USBController []string `mapstructure:"usb_controller"`
// VM notes.
Notes string `mapstructure:"notes"`
// If set to true, the VM will be destroyed after the builder completes
Destroy bool `mapstructure:"destroy"`
}

func (c *CreateConfig) Prepare() []error {
Expand Down Expand Up @@ -181,6 +183,9 @@ func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multiste
state.Put("error", fmt.Errorf("error creating vm: %v", err))
return multistep.ActionHalt
}
if s.Config.Destroy {
state.Put("destroy_vm", s.Config.Destroy)
}
state.Put("vm", vm)

return multistep.ActionContinue
Expand Down
2 changes: 2 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.

Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@

- `notes` (string) - VM notes.

- `destroy` (bool) - If set to true, the VM will be destroyed after the builder completes

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

0 comments on commit ff5bd54

Please sign in to comment.