Packer: virtualbox-vm builder crashes when no "attach_snapshot" is specified or is null

Created on 18 Mar 2020  ยท  7Comments  ยท  Source: hashicorp/packer

Overview of the Issue

The virtualbox-vm builder crashes if attach_snapshot is null, empty, or missing.

Reproduction Steps

In short: make a config that should load an existing, imported VM, leaving attach_snapshot out.

Example config:

{
   "builders": [
      {
         "disable_shutdown": "false",
         "guest_additions_mode": "disable",
         "headless": "true",
         "keep_registered": true,
         "name": "onprem-k8s-step",
         "output_directory": "./images/onprem_k8s",
         "shutdown_command": "/sbin/halt -p",
         "shutdown_timeout": "5m",
         "skip_export": true,
         "ssh_password": "changeme",
         "ssh_timeout": "5m",
         "ssh_username": "root",
         "target_snapshot": "step_00",
         "type": "virtualbox-vm",
         "vm_name": "onprem_k8s"
      }
   ],
   "provisioners": [
      {
         "inline": [
            "echo ==============================",
            "echo   Making initial snapshot...  ",
            "echo =============================="
         ],
         "type": "shell-local"
      }
   ]
}

Packer version

1.5.4

Operating system and Environment details

Linux x86-64, Pop OS 19.10, using precompiled binary

Log Fragments and crash.log files

Crash log atached

crash.log

bug buildevirtualbox regression track-internal virtualbox-vm

Most helpful comment

@onematchfox sorry, I didn't remember the context around those earlier PRs when I worked on this. I forgot there was a legitimate pathway here. I'll fix for the next release.

All 7 comments

Hi, thanks for opening this issue. I believe that It should be resolved by #8906 -- can you verify for me? Builds can be found at https://circleci.com/gh/hashicorp/packer/40076#artifacts/containers/0

That seems to have fixed it!

Hi @SwampDragons, Can you help me understand the reason snapshots became required again? Stumbled across this issue when upgrading now and unfortunately #8906 doesn't solve my issue because it still means the underlying VM must have a snapshot. This wasn't the case previously - see related PRs #8004 and #8096.

Here's an example workflow where the VM has no snapshot, nor is it required. E.g.:

{
  "variables": {
    "version": "{{env `VERSION`}}",
    "box_name": "{{env `BOX_NAME`}}"
  },
  "builders": [
    {
      "type": "virtualbox-vm",
      "communicator": "ssh",
      "ssh_username": "..",
      "ssh_private_key_file": "...",
      "shutdown_command": "sudo shutdown -h now",
      "guest_additions_mode": "disable",
      "output_directory": "./builds-vm",
      "vm_name": "{{user `box_name`}}",
      "format": "ova"
    }
  ],
  "post-processors": [
    [
      {
        "type": "amazon-import",
        "ami_name": "{{user `box_name`}}-{{user `version`}}",
        "ami_description": "AMI name",
        "region": "ca-central-1",
        "s3_bucket_name": "s3_amis",
     }
   ]
  ]
}

Essentially this workflow just loads the OVA, and then uses the resulting artifact in the Amazon import post processor. Perhaps I could achieve the same thing in a different way?

@onematchfox sorry, I didn't remember the context around those earlier PRs when I worked on this. I forgot there was a legitimate pathway here. I'll fix for the next release.

@onematchfox is totally right for the case of amazon-import, but logically also because virtualbox-vm as stated in the documentation, do exactly that (snapshot):

"The VirtualBox Packer builder is able to create VirtualBox virtual machines snapshots and (optionally) export them in the OVF format, starting from an existing virtual machine.

The builder builds a virtual machine snapshot by using an existing virtual machine, booting it, provisioning software within the OS, then shutting it down. The result of the VirtualBox builder is a new snapshot persisting all changes from the applied provisioners."

What about creating a snapshot and doing provisioning or post-processor for a vm not having a snapshot (so returing error) ? How to "automate" the process if you need to make a snapshot "manually" or "out of the packer process" ?

I'm missing something ?

Sorry for the delay on fixing this! I've just opened PR #8904 to solve this. Binaries of the patch can be found at https://circleci.com/gh/hashicorp/packer/60370#artifacts/containers/0, or you can wait for the 1.6.1 release.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings