Expose force_delete for openstack builder

Very similar to how its exposed in terraform adds an optional force_delete config entry on the openstack builder.
This commit is contained in:
josepand 2019-03-11 18:39:47 +00:00
parent 6e442e616c
commit f2b42f2b4b
4 changed files with 17 additions and 3 deletions

View File

@ -115,6 +115,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
ConfigDrive: b.config.ConfigDrive,
InstanceMetadata: b.config.InstanceMetadata,
UseBlockStorageVolume: b.config.UseBlockStorageVolume,
ForceDelete: b.config.ForceDelete,
},
&StepGetPassword{
Debug: b.config.PackerDebug,

View File

@ -31,6 +31,7 @@ type RunConfig struct {
UserDataFile string `mapstructure:"user_data_file"`
InstanceName string `mapstructure:"instance_name"`
InstanceMetadata map[string]string `mapstructure:"instance_metadata"`
ForceDelete bool `mapstructure:"force_delete"`
ConfigDrive bool `mapstructure:"config_drive"`

View File

@ -24,6 +24,7 @@ type StepRunSourceServer struct {
ConfigDrive bool
InstanceMetadata map[string]string
UseBlockStorageVolume bool
ForceDelete bool
server *servers.Server
}
@ -157,9 +158,16 @@ func (s *StepRunSourceServer) Cleanup(state multistep.StateBag) {
}
ui.Say(fmt.Sprintf("Terminating the source server: %s ...", s.server.ID))
if err := servers.Delete(computeClient, s.server.ID).ExtractErr(); err != nil {
ui.Error(fmt.Sprintf("Error terminating server, may still be around: %s", err))
return
if config.ForceDelete {
if err := servers.ForceDelete(computeClient, s.server.ID).ExtractErr(); err != nil {
ui.Error(fmt.Sprintf("Error terminating server, may still be around: %s", err))
return
}
} else {
if err := servers.Delete(computeClient, s.server.ID).ExtractErr(); err != nil {
ui.Error(fmt.Sprintf("Error terminating server, may still be around: %s", err))
return
}
}
stateChange := StateChangeConf{

View File

@ -136,6 +136,10 @@ builder.
- `floating_ip_pool` (string) - *Deprecated* use `floating_ip_network`
instead.
- `force_delete` (boolean) - Whether to force the OpenStack instance to be
forcefully deleted. This is useful for environments that have
reclaim / soft deletion enabled. By default this is false.
- `image_members` (array of strings) - List of members to add to the image
after creation. An image member is usually a project (also called the
"tenant") with whom the image is shared.