diff --git a/builder/nutanix/config.go b/builder/nutanix/config.go index 5a1495e..c5214b7 100644 --- a/builder/nutanix/config.go +++ b/builder/nutanix/config.go @@ -40,6 +40,7 @@ type Config struct { ImageDelete bool `mapstructure:"image_delete" json:"image_delete" required:"false"` ImageExport bool `mapstructure:"image_export" json:"image_export" required:"false"` WaitTimeout time.Duration `mapstructure:"ip_wait_timeout" json:"ip_wait_timeout" required:"false"` + ForceDelete bool `mapstructure:"force_delete" json:"force_delete" required:"false"` ctx interpolate.Context } diff --git a/builder/nutanix/config.hcl2spec.go b/builder/nutanix/config.hcl2spec.go index 71efded..4743750 100644 --- a/builder/nutanix/config.hcl2spec.go +++ b/builder/nutanix/config.hcl2spec.go @@ -152,6 +152,7 @@ type FlatConfig struct { ImageDelete *bool `mapstructure:"image_delete" json:"image_delete" required:"false" cty:"image_delete" hcl:"image_delete"` ImageExport *bool `mapstructure:"image_export" json:"image_export" required:"false" cty:"image_export" hcl:"image_export"` WaitTimeout *string `mapstructure:"ip_wait_timeout" json:"ip_wait_timeout" required:"false" cty:"ip_wait_timeout" hcl:"ip_wait_timeout"` + ForceDelete *bool `mapstructure:"force_delete" json:"force_delete" required:"false" cty:"force_delete" hcl:"force_delete"` } // FlatMapstructure returns a new FlatConfig. @@ -252,6 +253,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "image_delete": &hcldec.AttrSpec{Name: "image_delete", Type: cty.Bool, Required: false}, "image_export": &hcldec.AttrSpec{Name: "image_export", Type: cty.Bool, Required: false}, "ip_wait_timeout": &hcldec.AttrSpec{Name: "ip_wait_timeout", Type: cty.String, Required: false}, + "force_delete": &hcldec.AttrSpec{Name: "force_delete", Type: cty.Bool, Required: false}, } return s } diff --git a/builder/nutanix/step_build_vm.go b/builder/nutanix/step_build_vm.go index 1ea7562..f558348 100644 --- a/builder/nutanix/step_build_vm.go +++ b/builder/nutanix/step_build_vm.go @@ -79,19 +79,22 @@ func (s *stepBuildVM) Cleanup(state multistep.StateBag) { return } + ui := state.Get("ui").(packer.Ui) + d := state.Get("driver").(Driver) + config := state.Get("config").(*Config) + _, cancelled := state.GetOk(multistep.StateCancelled) _, halted := state.GetOk(multistep.StateHalted) - d := state.Get("driver").(Driver) - ui := state.Get("ui").(packer.Ui) - - if cancelled || halted { + if cancelled || halted && !config.ForceDelete { ui.Say("Task cancelled, virtual machine is not deleted") return + } else if config.ForceDelete && cancelled || halted { + ui.Say("Force Deleting virtual machine...") + } else { + ui.Say("Deleting virtual machine...") } - ui.Say("Deleting virtual machine...") - if cdUUID, ok := state.GetOk("cd_uuid"); ok { err := d.DeleteImage(cdUUID.(string)) if err != nil { diff --git a/docs/builders/nutanix.mdx b/docs/builders/nutanix.mdx index 4ebae15..d9221e1 100644 --- a/docs/builders/nutanix.mdx +++ b/docs/builders/nutanix.mdx @@ -33,6 +33,7 @@ These parameters allow to define information about platform and temporary VM use - `ip_wait_timeout` (duration string | ex: "0h42m0s") - Amount of time to wait for VM's IP, similar to 'ssh_timeout'. Defaults to 15m (15 minutes). See the Golang [ParseDuration](https://golang.org/pkg/time/#ParseDuration) documentation for full details. - `vm_categories` ([]Category) - Assign Categories to the vm. - `project` (string) - Assign Project to the vm. + - `force_delete` (bool) - Delete vm even if build is not succesful (default is false). ## Output configuration