Skip to content

Root block volumes not cleaned up when provisioning fails #243

@aslafy-z

Description

@aslafy-z

Overview of the Issue

In the case of failure, the root block volumes are not correctly deleted.

It looks like there are two cleanup places where volumes cleanup should be done:

With a config like this:

source "scaleway" "this" {
  # no block_volume block
  remove_volume  = true
}
  • step_create_server creates the server and volumes
  • step_create_volume does not create volumes as no additional block devices are configured

success:

  • step_create_server removes the server and keeps the root block volume dangling
  • step_create_volume removes the block volumes

failure:

  • step_create_server removes the server and keeps the root block volume dangling
  • step_create_volume does not remove the volume?

In the step_create_volume Cleanup steps, we see these:

Lines 74-86: Cleans up volumes only if the server was NOT created (!serverWasCreated)
Lines 88-117: Cleans up volumes only if snapshots exist (which happens much later in the build process)

Here are the changes I propose:

  • implement the root volume cleanup in the step_create_server Cleanup function
  • filter out root volume handling in the step_create_volume Cleanup function

Reproduction Steps

  • Start a build
  • Press Ctrl+C once the VM is provisioned, before snapshot creation.
  • See that a dangling volume exists.

Plugin and Packer version

  • plugin v1.3.2
  • packer v1.13.1

Simplified Packer Buildfile

packer {
  required_plugins {
    scaleway = {
      version = ">= 1.3.2"
      source  = "github.com/scaleway/scaleway"
    }
  }
}

source "scaleway" "this" {
  project_id      = "PROJECT_ID"
  zone            = "fr-par-1"
  image           = "docker"
  commercial_type = "DEV1-S"
  ssh_username    = "root"
  remove_volume   = true
}

build {
  name = "this"
  sources = [
    "source.scaleway.this"
  ]

  provisioner "shell" {
    inline = [
      "exit 1"
    ]
  }
}

Log Fragments and crash.log files

2025/07/18 13:24:01 packer-plugin-scaleway_v1.3.2_x5.0_linux_amd64 plugin: 2025/07/18 13:24:01 [ERROR] Remote command exited with '1': chmod +x /tmp/script_8460.sh; PACKER_BUILDER_TYPE='scaleway' PACKER_BUILD_NAME='this'  /tmp/script_8460.sh
2025/07/18 13:24:01 packer-plugin-scaleway_v1.3.2_x5.0_linux_amd64 plugin: 2025/07/18 13:24:01 [INFO] RPC endpoint: Communicator ended with: 1
2025/07/18 13:24:01 [INFO] 0 bytes written for 'stdout'
2025/07/18 13:24:01 [INFO] 0 bytes written for 'stderr'
2025/07/18 13:24:01 [INFO] RPC client: Communicator ended with: 1
2025/07/18 13:24:01 [INFO] RPC endpoint: Communicator ended with: 1
2025/07/18 13:24:01 packer-provisioner-shell plugin: [INFO] 0 bytes written for 'stdout'
2025/07/18 13:24:01 packer-provisioner-shell plugin: [INFO] 0 bytes written for 'stderr'
2025/07/18 13:24:01 packer-provisioner-shell plugin: [INFO] RPC client: Communicator ended with: 1
2025/07/18 13:24:01 [INFO] (telemetry) ending shell
==> this.scaleway.this: Provisioning step had errors: Running the cleanup provisioner, if present...
==> this.scaleway.this: Destroying server...
2025/07/18 13:24:01 [INFO] (telemetry) ending scaleway.this
==> Wait completed after 41 seconds 205 milliseconds
Build 'this.scaleway.this' errored after 41 seconds 205 milliseconds: Script exited with non-zero exit status: 1. Allowed exit codes are: [0]
2025/07/18 13:24:01 machine readable: error-count []string{"1"}

==> Some builds didn't complete successfully and had errors:
==> Wait completed after 41 seconds 205 milliseconds

2025/07/18 13:24:01 machine readable: this.scaleway.this,error []string{"Script exited with non-zero exit status: 1. Allowed exit codes are: [0]"}
==> Builds finished but no artifacts were created.
==> Some builds didn't complete successfully and had errors:
2025/07/18 13:24:01 [INFO] (telemetry) Finalizing.
--> this.scaleway.this: Script exited with non-zero exit status: 1. Allowed exit codes are: [0]

Metadata

Metadata

Assignees

Labels

bugpriority:mediumImprovements that are not the main priority

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions