feat: add 'remove volume' step to scaleway
Signed-off-by: Alexandre NICOLAIE <alexandre.nicolaie@gmail.com>
This commit is contained in:
parent
975ee377b2
commit
39b8c0ecca
|
@ -52,6 +52,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
|
|||
Debug: b.config.PackerDebug,
|
||||
DebugKeyPath: fmt.Sprintf("scw_%s.pem", b.config.PackerBuildName),
|
||||
},
|
||||
new(stepRemoveVolume),
|
||||
new(stepCreateServer),
|
||||
new(stepServerInfo),
|
||||
&communicator.StepConnect{
|
||||
|
|
|
@ -33,6 +33,8 @@ type Config struct {
|
|||
Bootscript string `mapstructure:"bootscript"`
|
||||
BootType string `mapstructure:"boottype"`
|
||||
|
||||
RemoveVolume bool `mapstructure:"remove_volume"`
|
||||
|
||||
UserAgent string
|
||||
ctx interpolate.Context
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package scaleway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/scaleway/scaleway-cli/pkg/api"
|
||||
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type stepRemoveVolume struct{}
|
||||
|
||||
func (s *stepRemoveVolume) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
// nothing to do ... only cleanup interests us
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *stepRemoveVolume) Cleanup(state multistep.StateBag) {
|
||||
client := state.Get("client").(*api.ScalewayAPI)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
c := state.Get("config").(*Config)
|
||||
volumeID := state.Get("root_volume_id").(string)
|
||||
|
||||
if !c.RemoveVolume {
|
||||
return
|
||||
}
|
||||
|
||||
ui.Say("Removing Volume ...")
|
||||
|
||||
err := client.DeleteVolume(volumeID)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error removing volume: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(fmt.Sprintf("Error removing volume: %s. (Ignored)", err))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue