Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update snapshots on step sweep #181

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builder/scaleway/builder_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func testAccPreCheck(t *testing.T) bool {

const testBuilderAccBasic = `
source "scaleway" "basic" {
commercial_type = "DEV1-S"
commercial_type = "PRO2-XXS"
remyleone marked this conversation as resolved.
Show resolved Hide resolved
image = "ubuntu_focal"
image_name = "Acceptance test"
ssh_username = "root"
Expand Down
1 change: 1 addition & 0 deletions builder/scaleway/step_create_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu
Name: c.ServerName,
Image: c.Image,
Tags: tags,
Zone: scw.Zone(c.Zone),
}

if c.ImageSizeInGB != 0 {
Expand Down
1 change: 1 addition & 0 deletions builder/scaleway/step_remove_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (s *stepRemoveVolume) Cleanup(state multistep.StateBag) {

err := instanceAPI.DeleteVolume(&instance.DeleteVolumeRequest{
VolumeID: volumeID,
Zone: scw.Zone(c.Zone),
})
if err != nil {
err := fmt.Errorf("error removing volume: %s", err)
Expand Down
2 changes: 2 additions & 0 deletions builder/scaleway/step_server_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ type stepServerInfo struct{}

func (s *stepServerInfo) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
instanceAPI := instance.NewAPI(state.Get("client").(*scw.Client))
c := state.Get("config").(*Config)
ui := state.Get("ui").(packersdk.Ui)
serverID := state.Get("server_id").(string)

ui.Say("Waiting for server to become active...")

instanceResp, err := instanceAPI.WaitForServer(&instance.WaitForServerRequest{
ServerID: serverID,
Zone: scw.Zone(c.Zone),
}, scw.WithContext(ctx))
if err != nil {
err := fmt.Errorf("error waiting for server to become booted: %s", err)
Expand Down
1 change: 1 addition & 0 deletions builder/scaleway/step_shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (s *stepShutdown) Run(ctx context.Context, state multistep.StateBag) multis
_, err := instanceAPI.ServerAction(&instance.ServerActionRequest{
Action: instance.ServerActionPoweroff,
ServerID: serverID,
Zone: scw.Zone(c.Zone),
}, scw.WithContext(ctx))
if err != nil {
err := fmt.Errorf("error stopping server: %s", err)
Expand Down
22 changes: 13 additions & 9 deletions builder/scaleway/step_sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ func (s *stepSweep) Run(_ context.Context, _ multistep.StateBag) multistep.StepA
func (s *stepSweep) Cleanup(state multistep.StateBag) {
instanceAPI := instance.NewAPI(state.Get("client").(*scw.Client))
ui := state.Get("ui").(packersdk.Ui)
snapshotID := state.Get("snapshot_id").(string)
c := state.Get("config").(*Config)
snapshots := state.Get("snapshots").([]ArtifactSnapshot)
imageID := state.Get("image_id").(string)

ui.Say("Deleting Image...")

err := instanceAPI.DeleteImage(&instance.DeleteImageRequest{
ImageID: imageID,
Zone: scw.Zone(c.Zone),
})
if err != nil {
err := fmt.Errorf("error deleting image: %s", err)
Expand All @@ -36,13 +38,15 @@ func (s *stepSweep) Cleanup(state multistep.StateBag) {

ui.Say("Deleting Snapshot...")

err = instanceAPI.DeleteSnapshot(&instance.DeleteSnapshotRequest{
SnapshotID: snapshotID,
})
if err != nil {
err := fmt.Errorf("error deleting snapshot: %s", err)
state.Put("error", err)
ui.Error(fmt.Sprintf("Error deleting snapshot: %s. (Ignored)", err))
for _, snapshot := range snapshots {
err = instanceAPI.DeleteSnapshot(&instance.DeleteSnapshotRequest{
SnapshotID: snapshot.ID,
remyleone marked this conversation as resolved.
Show resolved Hide resolved
Zone: scw.Zone(c.Zone),
})
if err != nil {
err := fmt.Errorf("error deleting snapshot: %s", err)
state.Put("error", err)
ui.Error(fmt.Sprintf("Error deleting snapshot: %s. (Ignored)", err))
}
}

}
Loading